diff options
author | 2022-07-09 19:03:40 +0200 | |
---|---|---|
committer | 2022-07-09 19:03:40 +0200 | |
commit | 9051dd6977d045f991092e247e6bd9da40d2e793 (patch) | |
tree | cde7d983ffc085ed908be776e9021a8e41b44b44 /examples/pure | |
parent | c4c1221be62f51dd9f1d20ea2c4ea6e2c94e20aa (diff) | |
parent | e548d6c0d5b430b090821e673dc453a24c885fbe (diff) | |
download | iced-9051dd6977d045f991092e247e6bd9da40d2e793.tar.gz iced-9051dd6977d045f991092e247e6bd9da40d2e793.tar.bz2 iced-9051dd6977d045f991092e247e6bd9da40d2e793.zip |
Merge pull request #1379 from PolyMeilex/fix/clippy
Address Clippy lints
Diffstat (limited to 'examples/pure')
-rw-r--r-- | examples/pure/component/src/main.rs | 3 | ||||
-rw-r--r-- | examples/pure/game_of_life/src/main.rs | 2 | ||||
-rw-r--r-- | examples/pure/game_of_life/src/preset.rs | 10 | ||||
-rw-r--r-- | examples/pure/todos/src/main.rs | 42 | ||||
-rw-r--r-- | examples/pure/tour/src/main.rs | 10 |
5 files changed, 29 insertions, 38 deletions
diff --git a/examples/pure/component/src/main.rs b/examples/pure/component/src/main.rs index 64935afd..db22d019 100644 --- a/examples/pure/component/src/main.rs +++ b/examples/pure/component/src/main.rs @@ -143,8 +143,7 @@ mod numeric_input { self.value .as_ref() .map(u32::to_string) - .as_ref() - .map(String::as_str) + .as_deref() .unwrap_or(""), Event::InputChanged, ) diff --git a/examples/pure/game_of_life/src/main.rs b/examples/pure/game_of_life/src/main.rs index 851fbd47..cf6560d6 100644 --- a/examples/pure/game_of_life/src/main.rs +++ b/examples/pure/game_of_life/src/main.rs @@ -350,7 +350,7 @@ mod grid { } } - pub fn view<'a>(&'a self) -> Element<'a, Message> { + pub fn view(&self) -> Element<Message> { Canvas::new(self) .width(Length::Fill) .height(Length::Fill) diff --git a/examples/pure/game_of_life/src/preset.rs b/examples/pure/game_of_life/src/preset.rs index 05157b6a..964b9120 100644 --- a/examples/pure/game_of_life/src/preset.rs +++ b/examples/pure/game_of_life/src/preset.rs @@ -1,7 +1,7 @@ #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub enum Preset { Custom, - XKCD, + Xkcd, Glider, SmallExploder, Exploder, @@ -14,7 +14,7 @@ pub enum Preset { pub static ALL: &[Preset] = &[ Preset::Custom, - Preset::XKCD, + Preset::Xkcd, Preset::Glider, Preset::SmallExploder, Preset::Exploder, @@ -30,7 +30,7 @@ impl Preset { #[rustfmt::skip] let cells = match self { Preset::Custom => vec![], - Preset::XKCD => vec![ + Preset::Xkcd => vec![ " xxx ", " x x ", " x x ", @@ -116,7 +116,7 @@ impl Preset { impl Default for Preset { fn default() -> Preset { - Preset::XKCD + Preset::Xkcd } } @@ -127,7 +127,7 @@ impl std::fmt::Display for Preset { "{}", match self { Preset::Custom => "Custom", - Preset::XKCD => "xkcd #2293", + Preset::Xkcd => "xkcd #2293", Preset::Glider => "Glider", Preset::SmallExploder => "Small Exploder", Preset::Exploder => "Exploder", diff --git a/examples/pure/todos/src/main.rs b/examples/pure/todos/src/main.rs index 723386ad..9a74ea71 100644 --- a/examples/pure/todos/src/main.rs +++ b/examples/pure/todos/src/main.rs @@ -167,7 +167,7 @@ impl Application for Todos { .size(30) .on_submit(Message::CreateTask); - let controls = view_controls(&tasks, *filter); + let controls = view_controls(tasks, *filter); let filtered_tasks = tasks.iter().filter(|task| filter.matches(task)); @@ -446,15 +446,15 @@ struct SavedState { #[derive(Debug, Clone)] enum LoadError { - FileError, - FormatError, + File, + Format, } #[derive(Debug, Clone)] enum SaveError { - FileError, - WriteError, - FormatError, + File, + Write, + Format, } #[cfg(not(target_arch = "wasm32"))] @@ -465,7 +465,7 @@ impl SavedState { { project_dirs.data_dir().into() } else { - std::env::current_dir().unwrap_or(std::path::PathBuf::new()) + std::env::current_dir().unwrap_or_default() }; path.push("todos.json"); @@ -480,37 +480,37 @@ impl SavedState { let mut file = async_std::fs::File::open(Self::path()) .await - .map_err(|_| LoadError::FileError)?; + .map_err(|_| LoadError::File)?; file.read_to_string(&mut contents) .await - .map_err(|_| LoadError::FileError)?; + .map_err(|_| LoadError::File)?; - serde_json::from_str(&contents).map_err(|_| LoadError::FormatError) + serde_json::from_str(&contents).map_err(|_| LoadError::Format) } async fn save(self) -> Result<(), SaveError> { use async_std::prelude::*; let json = serde_json::to_string_pretty(&self) - .map_err(|_| SaveError::FormatError)?; + .map_err(|_| SaveError::Format)?; let path = Self::path(); if let Some(dir) = path.parent() { async_std::fs::create_dir_all(dir) .await - .map_err(|_| SaveError::FileError)?; + .map_err(|_| SaveError::File)?; } { let mut file = async_std::fs::File::create(path) .await - .map_err(|_| SaveError::FileError)?; + .map_err(|_| SaveError::File)?; file.write_all(json.as_bytes()) .await - .map_err(|_| SaveError::WriteError)?; + .map_err(|_| SaveError::Write)?; } // This is a simple way to save at most once every couple seconds @@ -529,25 +529,25 @@ impl SavedState { } async fn load() -> Result<SavedState, LoadError> { - let storage = Self::storage().ok_or(LoadError::FileError)?; + let storage = Self::storage().ok_or(LoadError::File)?; let contents = storage .get_item("state") - .map_err(|_| LoadError::FileError)? - .ok_or(LoadError::FileError)?; + .map_err(|_| LoadError::File)? + .ok_or(LoadError::File)?; - serde_json::from_str(&contents).map_err(|_| LoadError::FormatError) + serde_json::from_str(&contents).map_err(|_| LoadError::Format) } async fn save(self) -> Result<(), SaveError> { - let storage = Self::storage().ok_or(SaveError::FileError)?; + let storage = Self::storage().ok_or(SaveError::File)?; let json = serde_json::to_string_pretty(&self) - .map_err(|_| SaveError::FormatError)?; + .map_err(|_| SaveError::Format)?; storage .set_item("state", &json) - .map_err(|_| SaveError::WriteError)?; + .map_err(|_| SaveError::Write)?; let _ = wasm_timer::Delay::new(std::time::Duration::from_secs(2)).await; diff --git a/examples/pure/tour/src/main.rs b/examples/pure/tour/src/main.rs index 477a1ec7..05c269c3 100644 --- a/examples/pure/tour/src/main.rs +++ b/examples/pure/tour/src/main.rs @@ -78,14 +78,6 @@ impl Sandbox for Tour { .push(controls) .into(); - let content = if self.debug { - // TODO - //content.explain(Color::BLACK) - content - } else { - content - }; - let scrollable = scrollable(container(content).width(Length::Fill).center_x()); @@ -494,7 +486,7 @@ impl<'a> Step { .push(ferris(width)) .push(slider(100..=500, width, StepMessage::ImageWidthChanged)) .push( - text(format!("Width: {} px", width.to_string())) + text(format!("Width: {} px", width)) .width(Length::Fill) .horizontal_alignment(alignment::Horizontal::Center), ) |