Skip to content

Commit

Permalink
clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
wash2 committed Oct 18, 2024
1 parent 909bb2b commit 79e74f5
Show file tree
Hide file tree
Showing 28 changed files with 55 additions and 71 deletions.
10 changes: 5 additions & 5 deletions accessibility/src/id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,12 @@ impl From<Id> for u64 {
}
}

impl ToString for Id {
fn to_string(&self) -> String {
impl std::fmt::Display for Id {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match &self.0 {
Internal::Unique(_) => "Undefined".to_string(),
Internal::Custom(_, id) => id.to_string(),
Internal::Set(_) => "Set".to_string(),
Internal::Unique(_) => write!(f, "Undefined"),
Internal::Custom(_, id) => write!(f, "{}", id.to_string()),
Internal::Set(_) => write!(f, "Set"),
}
}
}
Expand Down
17 changes: 6 additions & 11 deletions core/src/clipboard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub trait Clipboard {
/// Reads the current content of the [`Clipboard`] as text.
fn read_data(
&self,
kind: Kind,
_kind: Kind,
_mimes: Vec<String>,
) -> Option<(Vec<u8>, String)> {
None
Expand All @@ -29,7 +29,7 @@ pub trait Clipboard {
/// Writes the given contents to the [`Clipboard`].
fn write_data(
&mut self,
kind: Kind,
_kind: Kind,
_contents: ClipboardStoreData<
Box<dyn Send + Sync + 'static + mime::AsMimeTypes>,
>,
Expand Down Expand Up @@ -70,7 +70,7 @@ pub trait Clipboard {
}

/// Request window size
fn request_logical_window_size(&self, width: f32, height: f32) {}
fn request_logical_window_size(&self, _width: f32, _height: f32) {}
}

/// The kind of [`Clipboard`].
Expand Down Expand Up @@ -141,10 +141,7 @@ pub fn peek_dnd<T: AllowedMimeTypes>(
clipboard: &mut dyn Clipboard,
mime: Option<String>,
) -> Option<T> {
let Some(mime) = mime.or_else(|| T::allowed().first().cloned().into())
else {
return None;
};
let mime = mime.or_else(|| T::allowed().first().cloned())?;
clipboard
.peek_dnd(mime)
.and_then(|data| T::try_from(data).ok())
Expand All @@ -160,7 +157,7 @@ pub enum DndSource {
}

/// A list of DnD destination rectangles.
#[derive(Debug, Clone)]
#[derive(Debug, Clone, Default)]
pub struct DndDestinationRectangles {
/// The rectangle of the DnD destination.
rectangles: Vec<DndDestinationRectangle>,
Expand All @@ -169,9 +166,7 @@ pub struct DndDestinationRectangles {
impl DndDestinationRectangles {
/// Creates a new [`DndDestinationRectangles`].
pub fn new() -> Self {
Self {
rectangles: Vec::new(),
}
Self::default()
}

/// Creates a new [`DndDestinationRectangles`] with the given capacity.
Expand Down
2 changes: 1 addition & 1 deletion core/src/element.rs
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ where
}

fn diff(&mut self, tree: &mut Tree) {
self.widget.diff(tree)
self.widget.diff(tree);
}

fn size(&self) -> Size<Length> {
Expand Down
10 changes: 5 additions & 5 deletions core/src/id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,12 @@ impl From<Id> for NonZeroU128 {
}
}

impl ToString for Id {
fn to_string(&self) -> String {
impl std::fmt::Display for Id {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match &self.0 {
Internal::Unique(_) => "Undefined".to_string(),
Internal::Custom(_, id) => id.to_string(),
Internal::Set(_) => "Set".to_string(),
Internal::Unique(_) => write!(f, "Undefined"),
Internal::Custom(_, id) => write!(f, "{}", id.to_string()),

Check warning on line 67 in core/src/id.rs

View workflow job for this annotation

GitHub Actions / all

`to_string` applied to a type that implements `Display` in `write!` args

Check warning on line 67 in core/src/id.rs

View workflow job for this annotation

GitHub Actions / all

`to_string` applied to a type that implements `Display` in `write!` args
Internal::Set(_) => write!(f, "Set"),
}
}
}
Expand Down
1 change: 0 additions & 1 deletion core/src/overlay/group.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use crate::mouse;
use crate::overlay;
use crate::renderer;
use crate::widget;
use crate::widget::Operation;
use crate::{Clipboard, Event, Layout, Overlay, Point, Rectangle, Shell, Size};

/// An [`Overlay`] container that displays multiple overlay [`overlay::Element`]
Expand Down
2 changes: 1 addition & 1 deletion core/src/renderer/null.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::alignment;
use crate::image::{self, Image};
use crate::image;
use crate::renderer::{self, Renderer};
use crate::svg;
use crate::text::{self, Text};
Expand Down
1 change: 1 addition & 0 deletions core/src/theme.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ impl Theme {
}
}

#[allow(clippy::derivable_impls)]
impl Default for Theme {
fn default() -> Self {
#[cfg(feature = "auto-detect-theme")]
Expand Down
4 changes: 1 addition & 3 deletions core/src/widget/text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ use crate::{
Widget,
};

use std::borrow::Cow;

pub use text::{LineHeight, Shaping, Wrapping};

/// A bunch of text.
Expand Down Expand Up @@ -313,7 +311,7 @@ where
}

fn set_id(&mut self, id: crate::widget::Id) {
self.id = id
self.id = id;
}
}

Expand Down
4 changes: 2 additions & 2 deletions core/src/widget/tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,13 +269,13 @@ impl Tree {
new_children.iter().map(|c| c.borrow().id()).collect(),
|tree, widget| {
let borrowed: &mut dyn Widget<_, _, _> = widget.borrow_mut();
tree.diff(borrowed)
tree.diff(borrowed);
},
|widget| {
let borrowed: &dyn Widget<_, _, _> = widget.borrow();
Self::new(borrowed)
},
)
);
}

/// Reconciles the children of the tree with the provided list of widgets using custom
Expand Down
2 changes: 0 additions & 2 deletions graphics/src/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ pub use ::image as image_rs;

use crate::core::image;
use crate::core::svg;
use crate::core::Color;
use crate::core::Radians;
use crate::core::Rectangle;

/// A raster or vector image.
Expand Down
4 changes: 2 additions & 2 deletions graphics/src/text/paragraph.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
//! Draw paragraphs.
use crate::core;
use crate::core::alignment;
use crate::core::text::{Hit, LineHeight, Shaping, Span, Text, Wrapping};
use crate::core::{Font, Pixels, Point, Rectangle, Size};
use crate::core::text::{Hit, Shaping, Span, Text, Wrapping};
use crate::core::{Font, Point, Rectangle, Size};
use crate::text;

use std::fmt;
Expand Down
2 changes: 1 addition & 1 deletion renderer/src/fallback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::core::image;
use crate::core::renderer;
use crate::core::svg;
use crate::core::{
self, Background, Color, Image, Point, Rectangle, Size, Svg, Transformation,
self, Background, Color, Point, Rectangle, Size, Svg, Transformation,
};
use crate::graphics;
use crate::graphics::compositor;
Expand Down
4 changes: 2 additions & 2 deletions runtime/src/dnd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ pub fn peek_dnd<T: AllowedMimeTypes>() -> Task<Option<T>> {
task::oneshot(|tx| {
Action::Dnd(DndAction::PeekDnd(
T::allowed()
.get(0)
.map_or_else(|| String::new(), |s| s.to_string()),
.first()
.map_or_else(String::new, std::string::ToString::to_string),
tx,
))
})
Expand Down
4 changes: 1 addition & 3 deletions src/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,7 @@ use crate::runtime::{Appearance, DefaultStyle};
#[cfg(feature = "winit")]
pub use crate::shell::program::{Appearance, DefaultStyle};
use crate::window;
use crate::{
Element, Executor, Font, Result, Settings, Size, Subscription, Task,
};
use crate::{Element, Executor, Font, Settings, Size, Subscription, Task};

use std::borrow::Cow;

Expand Down
2 changes: 1 addition & 1 deletion src/daemon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::program::{self, Program};
#[cfg(feature = "winit")]
pub use crate::shell::program::{Appearance, DefaultStyle};
use crate::window;
use crate::{Element, Executor, Font, Result, Settings, Subscription, Task};
use crate::{Element, Executor, Font, Settings, Subscription, Task};

#[cfg(not(feature = "winit"))]
use crate::runtime::{Appearance, DefaultStyle};
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -663,7 +663,7 @@ pub type Element<
/// The result of running an iced program.
pub type Result = std::result::Result<(), Error>;

#[cfg(any(feature = "winit"))]
#[cfg(feature = "winit")]
/// Runs a basic iced application with default [`Settings`] given its title,
/// update, and view logic.
///
Expand Down
6 changes: 3 additions & 3 deletions tiny_skia/src/engine.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use tiny_skia::Transform;

use crate::core::renderer::Quad;
use crate::core::{
Background, Color, Gradient, Rectangle, Size, Transformation, Vector,
Expand Down Expand Up @@ -565,6 +563,8 @@ impl Engine {
match image {
#[cfg(feature = "image")]
Image::Raster { handle, bounds } => {
use tiny_skia::Transform;

let physical_bounds = *bounds * _transformation;

if !_clip_bounds.intersects(&physical_bounds) {
Expand Down Expand Up @@ -608,7 +608,7 @@ impl Engine {
let center = physical_bounds.center();
let radians = f32::from(handle.rotation);

let transform = Transform::default().post_rotate_at(
let transform = tiny_skia::Transform::default().post_rotate_at(
radians.to_degrees(),
center.x,
center.y,
Expand Down
6 changes: 3 additions & 3 deletions tiny_skia/src/layer.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::core::renderer::Quad;
use crate::core::{
self, Background, Color, Point, Radians, Rectangle, Svg, Transformation,
self, Background, Color, Point, Rectangle, Svg, Transformation,
};
use crate::graphics::damage;
use crate::graphics::layer;
Expand Down Expand Up @@ -118,10 +118,10 @@ impl Layer {
pub fn draw_image(&mut self, image: Image, transformation: Transformation) {
match image {
Image::Raster { handle, bounds } => {
self.draw_raster(handle, bounds, transformation)
self.draw_raster(handle, bounds, transformation);
}
Image::Vector { handle, bounds } => {
self.draw_svg(handle, bounds, transformation)
self.draw_svg(handle, bounds, transformation);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion widget/src/button.rs
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ where
}

fn diff(&mut self, tree: &mut Tree) {
tree.diff_children(std::slice::from_mut(&mut self.content))
tree.diff_children(std::slice::from_mut(&mut self.content));
}

fn size(&self) -> Size<Length> {
Expand Down
2 changes: 1 addition & 1 deletion widget/src/checkbox.rs
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ where
size,
line_height,
shaping,
wrap,
wrap: _,
} = &self.icon;
let size = size.unwrap_or(Pixels(bounds.height * 0.7));

Expand Down
2 changes: 1 addition & 1 deletion widget/src/container.rs
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,7 @@ pub fn visible_bounds(id: Id) -> Task<Option<Rectangle>> {
}

task::widget(VisibleBounds {
target: id.into(),
target: id,
depth: 0,
scrollables: Vec::new(),
bounds: None,
Expand Down
25 changes: 12 additions & 13 deletions widget/src/mouse_area.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,11 +165,11 @@ impl Default for State {
fn default() -> Self {
Self {
is_hovered: Default::default(),
drag_initiated: Default::default(),
drag_initiated: None,
is_out_of_bounds: true,
last_click: Default::default(),
last_click: None,
cursor_position: None,
bounds: Default::default(),
bounds: Rectangle::default(),
previous_click: None,
}
}
Expand Down Expand Up @@ -346,7 +346,7 @@ where
renderer: &Renderer,
dnd_rectangles: &mut crate::core::clipboard::DndDestinationRectangles,
) {
if let Some(state) = state.children.iter().next() {
if let Some(state) = state.children.first() {
self.content.as_widget().drag_destinations(
state,
layout,
Expand Down Expand Up @@ -415,20 +415,19 @@ fn update<Message: Clone, Theme, Renderer>(
}

if !cursor.is_over(layout.bounds()) {
if !state.is_out_of_bounds {
if widget
if !state.is_out_of_bounds
&& widget
.on_enter
.as_ref()
.or(widget.on_exit.as_ref())
.is_some()
{
if let Event::Mouse(mouse::Event::CursorMoved { .. }) = event {
state.is_out_of_bounds = true;
if let Some(message) = widget.on_exit.as_ref() {
shell.publish(message.clone());
}
return event::Status::Captured;
{
if let Event::Mouse(mouse::Event::CursorMoved { .. }) = event {
state.is_out_of_bounds = true;
if let Some(message) = widget.on_exit.as_ref() {
shell.publish(message.clone());
}
return event::Status::Captured;
}
}

Expand Down
2 changes: 1 addition & 1 deletion widget/src/pane_grid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ where
ids,
|state, (_, content)| content.diff(state),
|(_, content)| content.state(),
)
);
}
Contents::Maximized(_, content, _) => tree.diff_children_custom(
&mut [content],
Expand Down
2 changes: 0 additions & 2 deletions widget/src/pane_grid/content.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use iced_renderer::core::widget::Operation;

use crate::container;
use crate::core::event::{self, Event};
use crate::core::layout;
Expand Down
2 changes: 0 additions & 2 deletions widget/src/pane_grid/title_bar.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use iced_renderer::core::widget::Operation;

use crate::container;
use crate::core::event::{self, Event};
use crate::core::layout;
Expand Down
2 changes: 1 addition & 1 deletion widget/src/row.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ where
}

fn diff(&mut self, tree: &mut Tree) {
tree.diff_children(&mut self.children)
tree.diff_children(&mut self.children);
}

fn size(&self) -> Size<Length> {
Expand Down
2 changes: 1 addition & 1 deletion widget/src/scrollable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ where
}

fn diff(&mut self, tree: &mut Tree) {
tree.diff_children(std::slice::from_mut(&mut self.content))
tree.diff_children(std::slice::from_mut(&mut self.content));
}

fn size(&self) -> Size<Length> {
Expand Down
Loading

0 comments on commit 79e74f5

Please sign in to comment.