Miscellaneous small changes (#1238)

* Use a slice instead of a new object

* Remove unnecessary 'into_iter'

* Use 'and_then' instead of 'map_or'
This commit is contained in:
David Sinclair 2019-10-24 01:45:25 +02:00 committed by Osspial
parent 6608a0241d
commit 05a1f4280c
3 changed files with 2 additions and 6 deletions

View file

@ -208,7 +208,7 @@ pub fn scancode_to_keycode(scancode: c_ushort) -> Option<VirtualKeyCode> {
// While F1-F20 have scancodes we can match on, we have to check against UTF-16 // While F1-F20 have scancodes we can match on, we have to check against UTF-16
// constants for the rest. // constants for the rest.
// https://developer.apple.com/documentation/appkit/1535851-function-key_unicodes?preferredLanguage=occ // https://developer.apple.com/documentation/appkit/1535851-function-key_unicodes?preferredLanguage=occ
pub fn check_function_keys(string: &String) -> Option<VirtualKeyCode> { pub fn check_function_keys(string: &str) -> Option<VirtualKeyCode> {
if let Some(ch) = string.encode_utf16().next() { if let Some(ch) = string.encode_utf16().next() {
return Some(match ch { return Some(match ch {
0xf718 => VirtualKeyCode::F21, 0xf718 => VirtualKeyCode::F21,

View file

@ -248,7 +248,6 @@ impl MonitorHandle {
assert!(!array.is_null(), "failed to get list of display modes"); assert!(!array.is_null(), "failed to get list of display modes");
let array_count = CFArrayGetCount(array); let array_count = CFArrayGetCount(array);
let modes: Vec<_> = (0..array_count) let modes: Vec<_> = (0..array_count)
.into_iter()
.map(move |i| { .map(move |i| {
let mode = CFArrayGetValueAtIndex(array, i) as *mut _; let mode = CFArrayGetValueAtIndex(array, i) as *mut _;
ffi::CGDisplayModeRetain(mode); ffi::CGDisplayModeRetain(mode);

View file

@ -520,10 +520,7 @@ fn retrieve_keycode(event: id) -> Option<VirtualKeyCode> {
#[inline] #[inline]
fn get_code(ev: id, raw: bool) -> Option<VirtualKeyCode> { fn get_code(ev: id, raw: bool) -> Option<VirtualKeyCode> {
let characters = get_characters(ev, raw); let characters = get_characters(ev, raw);
characters characters.chars().next().and_then(|c| char_to_keycode(c))
.chars()
.next()
.map_or(None, |c| char_to_keycode(c))
} }
// Cmd switches Roman letters for Dvorak-QWERTY layout, so we try modified characters first. // Cmd switches Roman letters for Dvorak-QWERTY layout, so we try modified characters first.