1
0
mirror of https://github.com/emilk/egui.git synced 2026-09-01 14:20:04 -04:00

use map_or and map_or_else

This commit is contained in:
Emil Ernerfeldt
2021-10-20 16:33:59 +02:00
parent a0cd41755e
commit 40445c450c
8 changed files with 26 additions and 41 deletions

View File

@@ -150,8 +150,7 @@ fn remove_leading_indentation(code: &str) -> String {
let start = first_line_indent.min(indent);
let end = code
.find('\n')
.map(|endline| endline + 1)
.unwrap_or_else(|| code.len());
.map_or_else(|| code.len(), |endline| endline + 1);
out += &code[start..end];
code = &code[end..];
}

View File

@@ -49,11 +49,7 @@ impl super::View for MultiTouch {
ui.separator();
ui.label("Try touch gestures Pinch/Stretch, Rotation, and Pressure with 2+ fingers.");
let num_touches = ui
.input()
.multi_touch()
.map(|mt| mt.num_touches)
.unwrap_or(0);
let num_touches = ui.input().multi_touch().map_or(0, |mt| mt.num_touches);
ui.label(format!("Current touches: {}", num_touches));
Frame::dark_canvas(ui.style()).show(ui, |ui| {