Fix clippy lints for all crates and features

... and check those in CI as well!
This commit is contained in:
Héctor Ramón Jiménez 2022-07-09 18:42:41 +02:00
parent d53cc5498b
commit 2065a40f64
No known key found for this signature in database
GPG key ID: 140CC052C94F138E
55 changed files with 237 additions and 232 deletions

View file

@ -84,7 +84,7 @@ impl Sandbox for ColorPalette {
}
#[derive(Debug)]
pub struct Theme {
struct Theme {
lower: Vec<Color>,
base: Color,
higher: Vec<Color>,

View file

@ -150,8 +150,7 @@ mod numeric_input {
self.value
.as_ref()
.map(u32::to_string)
.as_ref()
.map(String::as_str)
.as_deref()
.unwrap_or(""),
Event::InputChanged,
)

View file

@ -64,12 +64,12 @@ mod circle {
}
}
impl<'a, Message, Renderer> Into<Element<'a, Message, Renderer>> for Circle
impl<'a, Message, Renderer> From<Circle> for Element<'a, Message, Renderer>
where
Renderer: renderer::Renderer,
{
fn into(self) -> Element<'a, Message, Renderer> {
Element::new(self)
fn from(circle: Circle) -> Self {
Self::new(circle)
}
}
}

View file

@ -49,7 +49,7 @@ impl Application for Example {
fn update(&mut self, message: Message) -> Command<Message> {
match message {
Message::Add => {
self.last_id = self.last_id + 1;
self.last_id += 1;
self.downloads.push(Download::new(self.last_id));
}
@ -134,8 +134,8 @@ impl Download {
}
pub fn progress(&mut self, new_progress: download::Progress) {
match &mut self.state {
State::Downloading { progress } => match new_progress {
if let State::Downloading { progress } = &mut self.state {
match new_progress {
download::Progress::Started => {
*progress = 0.0;
}
@ -152,8 +152,7 @@ impl Download {
button: button::State::new(),
};
}
},
_ => {}
}
}
}

View file

@ -280,7 +280,7 @@ mod grid {
}
}
pub fn view<'a>(&'a mut self) -> Element<'a, Message> {
pub fn view(&mut self) -> Element<Message> {
Canvas::new(self)
.width(Length::Fill)
.height(Length::Fill)
@ -328,7 +328,7 @@ mod grid {
}
}
impl<'a> canvas::Program<Message> for Grid {
impl canvas::Program<Message> for Grid {
fn update(
&mut self,
event: Event,
@ -826,13 +826,13 @@ struct Controls {
}
impl Controls {
fn view<'a>(
&'a mut self,
fn view(
&mut self,
is_playing: bool,
is_grid_enabled: bool,
speed: usize,
preset: Preset,
) -> Element<'a, Message> {
) -> Element<Message> {
let playback_controls = Row::new()
.spacing(10)
.push(

View file

@ -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",

View file

@ -17,6 +17,7 @@ mod rainbow {
layout, Element, Layout, Length, Point, Rectangle, Size, Vector, Widget,
};
#[derive(Default)]
pub struct Rainbow;
impl Rainbow {
@ -148,12 +149,12 @@ mod rainbow {
}
}
impl<'a, Message, B, T> Into<Element<'a, Message, Renderer<B, T>>> for Rainbow
impl<'a, Message, B, T> From<Rainbow> for Element<'a, Message, Renderer<B, T>>
where
B: Backend,
{
fn into(self) -> Element<'a, Message, Renderer<B, T>> {
Element::new(self)
fn from(rainbow: Rainbow) -> Self {
Self::new(rainbow)
}
}
}

View file

@ -58,7 +58,7 @@ pub fn main() {
let mut cursor_position = PhysicalPosition::new(-1.0, -1.0);
let mut modifiers = ModifiersState::default();
let mut clipboard = Clipboard::connect(&windowed_context.window());
let mut clipboard = Clipboard::connect(windowed_context.window());
let mut renderer = Renderer::new(Backend::new(&gl, Settings::default()));
@ -73,13 +73,12 @@ pub fn main() {
);
let mut resized = false;
let scene = Scene::new(&gl, &shader_version);
let scene = Scene::new(&gl, shader_version);
event_loop.run(move |event, _, control_flow| {
*control_flow = ControlFlow::Wait;
match event {
Event::LoopDestroyed => return,
Event::WindowEvent { event, .. } => {
match event {
WindowEvent::CursorMoved { position, .. } => {

View file

@ -112,7 +112,7 @@ impl Program for Controls {
t,
"Placeholder",
text,
move |text| Message::TextChanged(text),
Message::TextChanged,
)),
),
)

View file

@ -73,7 +73,7 @@ pub fn main() {
let instance = wgpu::Instance::new(backend);
let surface = unsafe { instance.create_surface(&window) };
let (format, (mut device, queue)) = futures::executor::block_on(async {
let (format, (device, queue)) = futures::executor::block_on(async {
let adapter = wgpu::util::initialize_adapter_from_env_or_default(
&instance,
backend,
@ -128,13 +128,13 @@ pub fn main() {
let mut staging_belt = wgpu::util::StagingBelt::new(5 * 1024);
// Initialize scene and GUI controls
let scene = Scene::new(&mut device, format);
let scene = Scene::new(&device, format);
let controls = Controls::new();
// Initialize iced
let mut debug = Debug::new();
let mut renderer =
Renderer::new(Backend::new(&mut device, Settings::default(), format));
Renderer::new(Backend::new(&device, Settings::default(), format));
let mut state = program::State::new(
controls,
@ -208,8 +208,8 @@ pub fn main() {
surface.configure(
&device,
&wgpu::SurfaceConfiguration {
format,
usage: wgpu::TextureUsages::RENDER_ATTACHMENT,
format: format,
width: size.width,
height: size.height,
present_mode: wgpu::PresentMode::AutoVsync,
@ -244,7 +244,7 @@ pub fn main() {
// And then iced on top
renderer.with_primitives(|backend, primitive| {
backend.present(
&mut device,
&device,
&mut staging_belt,
&mut encoder,
&view,

View file

@ -66,40 +66,37 @@ fn build_pipeline(
bind_group_layouts: &[],
});
let pipeline =
device.create_render_pipeline(&wgpu::RenderPipelineDescriptor {
label: None,
layout: Some(&pipeline_layout),
vertex: wgpu::VertexState {
module: &vs_module,
entry_point: "main",
buffers: &[],
},
fragment: Some(wgpu::FragmentState {
module: &fs_module,
entry_point: "main",
targets: &[Some(wgpu::ColorTargetState {
format: texture_format,
blend: Some(wgpu::BlendState {
color: wgpu::BlendComponent::REPLACE,
alpha: wgpu::BlendComponent::REPLACE,
}),
write_mask: wgpu::ColorWrites::ALL,
})],
}),
primitive: wgpu::PrimitiveState {
topology: wgpu::PrimitiveTopology::TriangleList,
front_face: wgpu::FrontFace::Ccw,
..Default::default()
},
depth_stencil: None,
multisample: wgpu::MultisampleState {
count: 1,
mask: !0,
alpha_to_coverage_enabled: false,
},
multiview: None,
});
pipeline
device.create_render_pipeline(&wgpu::RenderPipelineDescriptor {
label: None,
layout: Some(&pipeline_layout),
vertex: wgpu::VertexState {
module: &vs_module,
entry_point: "main",
buffers: &[],
},
fragment: Some(wgpu::FragmentState {
module: &fs_module,
entry_point: "main",
targets: &[Some(wgpu::ColorTargetState {
format: texture_format,
blend: Some(wgpu::BlendState {
color: wgpu::BlendComponent::REPLACE,
alpha: wgpu::BlendComponent::REPLACE,
}),
write_mask: wgpu::ColorWrites::ALL,
})],
}),
primitive: wgpu::PrimitiveState {
topology: wgpu::PrimitiveTopology::TriangleList,
front_face: wgpu::FrontFace::Ccw,
..Default::default()
},
depth_stencil: None,
multisample: wgpu::MultisampleState {
count: 1,
mask: !0,
alpha_to_coverage_enabled: false,
},
multiview: None,
})
}

View file

@ -192,8 +192,7 @@ impl Pokemon {
let description = entry
.flavor_text_entries
.iter()
.filter(|text| text.language.name == "en")
.next()
.find(|text| text.language.name == "en")
.ok_or(Error::LanguageError)?;
Ok(Pokemon {

View file

@ -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,
)

View file

@ -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)

View file

@ -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",

View file

@ -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

View file

@ -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),
)

View file

@ -65,8 +65,7 @@ impl Application for SolarSystem {
}
fn subscription(&self) -> Subscription<Message> {
time::every(std::time::Duration::from_millis(10))
.map(|instant| Message::Tick(instant))
time::every(std::time::Duration::from_millis(10)).map(Message::Tick)
}
fn view(&mut self) -> Element<Message> {

View file

@ -67,13 +67,12 @@ impl Application for Stopwatch {
self.state = State::Idle;
}
},
Message::Tick(now) => match &mut self.state {
State::Ticking { last_tick } => {
Message::Tick(now) => {
if let State::Ticking { last_tick } = &mut self.state {
self.duration += now - *last_tick;
*last_tick = now;
}
_ => {}
},
}
Message::Reset => {
self.duration = Duration::default();
}

View file

@ -107,11 +107,8 @@ impl Application for Example {
ByteSize::kb(information.memory_total).to_string();
let memory_total = Text::new(format!(
"Memory (total): {}",
format!(
"{} kb ({})",
information.memory_total, memory_readable
)
"Memory (total): {} kb ({})",
information.memory_total, memory_readable
));
let memory_text = if let Some(memory_used) =

View file

@ -168,7 +168,7 @@ impl Application for Todos {
.size(30)
.on_submit(Message::CreateTask);
let controls = controls.view(&tasks, *filter);
let controls = controls.view(tasks, *filter);
let filtered_tasks =
tasks.iter().filter(|task| filter.matches(task));
@ -493,15 +493,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"))]
@ -512,7 +512,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");
@ -527,37 +527,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

View file

@ -54,16 +54,11 @@ impl Sandbox for Example {
tooltip::Position::Right,
);
let fixed_tooltips = Row::with_children(vec![
top.into(),
bottom.into(),
left.into(),
right.into(),
])
.width(Length::Fill)
.height(Length::Fill)
.align_items(Alignment::Center)
.spacing(50);
let fixed_tooltips = Row::with_children(vec![top, bottom, left, right])
.width(Length::Fill)
.height(Length::Fill)
.align_items(Alignment::Center)
.spacing(50);
let follow_cursor = tooltip(
"Tooltip follows cursor",
@ -78,7 +73,7 @@ impl Sandbox for Example {
.center_x()
.center_y()
.into(),
follow_cursor.into(),
follow_cursor,
])
.width(Length::Fill)
.height(Length::Fill)

View file

@ -57,7 +57,7 @@ impl Application for App {
fn view(&mut self) -> Element<Message> {
let content = match &self.url {
Some(url) => Text::new(format!("{}", url)),
Some(url) => Text::new(url),
None => Text::new("No URL received yet!"),
};

View file

@ -32,7 +32,7 @@ pub fn connect() -> Subscription<Event> {
)
}
Err(_) => {
let _ = tokio::time::sleep(
tokio::time::sleep(
tokio::time::Duration::from_secs(1),
)
.await;
@ -79,6 +79,7 @@ pub fn connect() -> Subscription<Event> {
}
#[derive(Debug)]
#[allow(clippy::large_enum_variant)]
enum State {
Disconnected,
Connected(
@ -101,8 +102,7 @@ pub struct Connection(mpsc::Sender<Message>);
impl Connection {
pub fn send(&mut self, message: Message) {
let _ = self
.0
self.0
.try_send(message)
.expect("Send message to echo server");
}

View file

@ -27,9 +27,9 @@ use warp::Filter;
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
pub async fn run() {
let routes = warp::path::end().and(warp::ws()).map(|ws: warp::ws::Ws| {
ws.on_upgrade(move |socket| user_connected(socket))
});
let routes = warp::path::end()
.and(warp::ws())
.map(|ws: warp::ws::Ws| ws.on_upgrade(user_connected));
warp::serve(routes).run(([127, 0, 0, 1], 3030)).await;
}
@ -40,7 +40,7 @@ async fn user_connected(ws: WebSocket) {
tokio::task::spawn(async move {
while let Some(message) = rx.next().await {
let _ = user_ws_tx.send(message).await.unwrap_or_else(|e| {
user_ws_tx.send(message).await.unwrap_or_else(|e| {
eprintln!("websocket send error: {}", e);
});
}