Address Clippy lints

This commit is contained in:
Poly 2022-07-04 01:17:29 +02:00 committed by Héctor Ramón Jiménez
parent e053e25d2c
commit 15f794b7a8
No known key found for this signature in database
GPG key ID: 140CC052C94F138E
43 changed files with 147 additions and 172 deletions

View file

@ -1,13 +1,7 @@
/// The hasher used to compare layouts.
#[derive(Debug)]
#[derive(Debug, Default)]
pub struct Hasher(twox_hash::XxHash64);
impl Default for Hasher {
fn default() -> Self {
Hasher(twox_hash::XxHash64::default())
}
}
impl core::hash::Hasher for Hasher {
fn write(&mut self, bytes: &[u8]) {
self.0.write(bytes)

View file

@ -174,9 +174,9 @@ where
Self {
container,
width: width,
width,
target_height,
style: style,
style,
}
}
}
@ -230,7 +230,7 @@ where
shell: &mut Shell<'_, Message>,
) -> event::Status {
self.container.on_event(
event.clone(),
event,
layout,
cursor_position,
renderer,
@ -326,7 +326,8 @@ where
use std::f32;
let limits = limits.width(Length::Fill).height(Length::Shrink);
let text_size = self.text_size.unwrap_or(renderer.default_size());
let text_size =
self.text_size.unwrap_or_else(|| renderer.default_size());
let size = {
let intrinsic = Size::new(
@ -366,8 +367,9 @@ where
let bounds = layout.bounds();
if bounds.contains(cursor_position) {
let text_size =
self.text_size.unwrap_or(renderer.default_size());
let text_size = self
.text_size
.unwrap_or_else(|| renderer.default_size());
*self.hovered_option = Some(
((cursor_position.y - bounds.y)
@ -380,8 +382,9 @@ where
let bounds = layout.bounds();
if bounds.contains(cursor_position) {
let text_size =
self.text_size.unwrap_or(renderer.default_size());
let text_size = self
.text_size
.unwrap_or_else(|| renderer.default_size());
*self.hovered_option = Some(
((cursor_position.y - bounds.y)
@ -430,7 +433,8 @@ where
let appearance = theme.appearance(self.style);
let bounds = layout.bounds();
let text_size = self.text_size.unwrap_or(renderer.default_size());
let text_size =
self.text_size.unwrap_or_else(|| renderer.default_size());
let option_height = (text_size + self.padding.vertical()) as usize;
let offset = viewport.y - bounds.y;

View file

@ -113,7 +113,7 @@ where
&mut messages,
);
messages.extend(self.queued_messages.drain(..));
messages.append(&mut self.queued_messages);
self.queued_events.clear();
debug.event_processing_finished();

View file

@ -430,7 +430,7 @@ where
overlay
.as_ref()
.and_then(|layout| {
root.overlay(Layout::new(&base), renderer).map(|overlay| {
root.overlay(Layout::new(base), renderer).map(|overlay| {
let overlay_interaction = overlay.mouse_interaction(
Layout::new(layout),
cursor_position,

View file

@ -158,7 +158,10 @@ where
Text::new(&self.label)
.font(self.font.clone())
.width(self.width)
.size(self.text_size.unwrap_or(renderer.default_size())),
.size(
self.text_size
.unwrap_or_else(|| renderer.default_size()),
),
)
.layout(renderer, limits)
}

View file

@ -835,8 +835,7 @@ fn hovered_split<'a>(
) -> Option<(Split, Axis, Rectangle)> {
splits
.filter_map(|(split, (axis, region, ratio))| {
let bounds =
axis.split_line_bounds(*region, *ratio, f32::from(spacing));
let bounds = axis.split_line_bounds(*region, *ratio, spacing);
if bounds.contains(cursor_position) {
Some((*split, *axis, bounds))

View file

@ -36,14 +36,11 @@ impl Node {
std::iter::from_fn(move || {
while let Some(node) = unvisited_nodes.pop() {
match node {
Node::Split { id, a, b, .. } => {
unvisited_nodes.push(a);
unvisited_nodes.push(b);
if let Node::Split { id, a, b, .. } = node {
unvisited_nodes.push(a);
unvisited_nodes.push(b);
return Some(id);
}
_ => {}
return Some(id);
}
}
@ -124,12 +121,9 @@ impl Node {
}
pub(crate) fn update(&mut self, f: &impl Fn(&mut Node)) {
match self {
Node::Split { a, b, .. } => {
a.update(f);
b.update(f);
}
_ => {}
if let Node::Split { a, b, .. } = self {
a.update(f);
b.update(f);
}
f(self);

View file

@ -66,6 +66,11 @@ impl<T> State<T> {
self.panes.len()
}
/// Returns `true` if the amount of panes in the [`State`] is 0.
pub fn is_empty(&self) -> bool {
self.len() == 0
}
/// Returns the internal state of the given [`Pane`], if it exists.
pub fn get(&self, pane: &Pane) -> Option<&T> {
self.panes.get(pane)

View file

@ -160,7 +160,7 @@ where
let limits = limits.width(width).height(Length::Shrink).pad(padding);
let text_size = text_size.unwrap_or(renderer.default_size());
let text_size = text_size.unwrap_or_else(|| renderer.default_size());
let max_width = match width {
Length::Shrink => {
@ -407,10 +407,9 @@ pub fn draw<T, Renderer>(
let label = selected.map(ToString::to_string);
if let Some(label) =
label.as_ref().map(String::as_str).or_else(|| placeholder)
{
let text_size = f32::from(text_size.unwrap_or(renderer.default_size()));
if let Some(label) = label.as_deref().or(placeholder) {
let text_size =
f32::from(text_size.unwrap_or_else(|| renderer.default_size()));
renderer.fill_text(Text {
content: label,
@ -460,7 +459,7 @@ where
self.padding,
self.text_size,
&self.font,
self.placeholder.as_ref().map(String::as_str),
self.placeholder.as_deref(),
&self.options,
)
}
@ -513,7 +512,7 @@ where
self.padding,
self.text_size,
&self.font,
self.placeholder.as_ref().map(String::as_str),
self.placeholder.as_deref(),
self.selected.as_ref(),
self.style,
)

View file

@ -168,11 +168,9 @@ where
.width(Length::Units(self.size))
.height(Length::Units(self.size)),
)
.push(
Text::new(&self.label)
.width(self.width)
.size(self.text_size.unwrap_or(renderer.default_size())),
)
.push(Text::new(&self.label).width(self.width).size(
self.text_size.unwrap_or_else(|| renderer.default_size()),
))
.layout(renderer, limits)
}

View file

@ -36,7 +36,7 @@ where
/// Creates a vertical [`Rule`] with the given width.
pub fn vertical(width: u16) -> Self {
Rule {
width: Length::from(Length::Units(width)),
width: Length::Units(width),
height: Length::Fill,
is_horizontal: false,
style: Default::default(),

View file

@ -303,7 +303,7 @@ pub fn draw<T, R>(
HandleShape::Rectangle {
width,
border_radius,
} => (f32::from(width), f32::from(bounds.height), border_radius),
} => (f32::from(width), bounds.height, border_radius),
};
let value = value.into() as f32;
@ -447,7 +447,7 @@ where
_viewport: &Rectangle,
_renderer: &Renderer,
) -> mouse::Interaction {
mouse_interaction(layout, cursor_position, &self.state)
mouse_interaction(layout, cursor_position, self.state)
}
}

View file

@ -131,7 +131,7 @@ where
) -> layout::Node {
let limits = limits.width(self.width).height(self.height);
let size = self.size.unwrap_or(renderer.default_size());
let size = self.size.unwrap_or_else(|| renderer.default_size());
let bounds = limits.max();
@ -205,7 +205,7 @@ pub fn draw<Renderer>(
renderer.fill_text(crate::text::Text {
content,
size: f32::from(size.unwrap_or(renderer.default_size())),
size: f32::from(size.unwrap_or_else(|| renderer.default_size())),
bounds: Rectangle { x, y, ..bounds },
color: appearance.color.unwrap_or(style.text_color),
font,

View file

@ -198,7 +198,7 @@ pub fn layout<Renderer>(
where
Renderer: text::Renderer,
{
let text_size = size.unwrap_or(renderer.default_size());
let text_size = size.unwrap_or_else(|| renderer.default_size());
let limits = limits
.pad(padding)
@ -498,7 +498,7 @@ where
None => {
let content: String = clipboard
.read()
.unwrap_or(String::new())
.unwrap_or_default()
.chars()
.filter(|c| !c.is_control())
.collect();
@ -597,7 +597,7 @@ pub fn draw<Renderer>(
Renderer::Theme: StyleSheet,
{
let secure_value = is_secure.then(|| value.secure());
let value = secure_value.as_ref().unwrap_or(&value);
let value = secure_value.as_ref().unwrap_or(value);
let bounds = layout.bounds();
let text_bounds = layout.children().next().unwrap().bounds();
@ -623,16 +623,16 @@ pub fn draw<Renderer>(
);
let text = value.to_string();
let size = size.unwrap_or(renderer.default_size());
let size = size.unwrap_or_else(|| renderer.default_size());
let (cursor, offset) = if state.is_focused() {
match state.cursor.state(&value) {
match state.cursor.state(value) {
cursor::State::Index(position) => {
let (text_value_width, offset) =
measure_cursor_and_scroll_offset(
renderer,
text_bounds,
&value,
value,
size,
position,
font.clone(),
@ -664,7 +664,7 @@ pub fn draw<Renderer>(
measure_cursor_and_scroll_offset(
renderer,
text_bounds,
&value,
value,
size,
left,
font.clone(),
@ -674,7 +674,7 @@ pub fn draw<Renderer>(
measure_cursor_and_scroll_offset(
renderer,
text_bounds,
&value,
value,
size,
right,
font.clone(),
@ -998,16 +998,16 @@ fn find_cursor_position<Renderer>(
where
Renderer: text::Renderer,
{
let size = size.unwrap_or(renderer.default_size());
let size = size.unwrap_or_else(|| renderer.default_size());
let offset =
offset(renderer, text_bounds, font.clone(), size, &value, &state);
offset(renderer, text_bounds, font.clone(), size, value, state);
renderer
.hit_test(
&value.to_string(),
size.into(),
font.clone(),
font,
Size::INFINITY,
Point::new(x + offset, text_bounds.height / 2.0),
true,

View file

@ -15,12 +15,9 @@ impl<'a> Editor<'a> {
}
pub fn insert(&mut self, character: char) {
match self.cursor.selection(self.value) {
Some((left, right)) => {
self.cursor.move_left(self.value);
self.value.remove_many(left, right);
}
_ => {}
if let Some((left, right)) = self.cursor.selection(self.value) {
self.cursor.move_left(self.value);
self.value.remove_many(left, right);
}
self.value.insert(self.cursor.end(self.value), character);
@ -29,13 +26,9 @@ impl<'a> Editor<'a> {
pub fn paste(&mut self, content: Value) {
let length = content.len();
match self.cursor.selection(self.value) {
Some((left, right)) => {
self.cursor.move_left(self.value);
self.value.remove_many(left, right);
}
_ => {}
if let Some((left, right)) = self.cursor.selection(self.value) {
self.cursor.move_left(self.value);
self.value.remove_many(left, right);
}
self.value.insert_many(self.cursor.end(self.value), content);

View file

@ -37,7 +37,7 @@ impl Value {
let previous_string =
&self.graphemes[..index.min(self.graphemes.len())].concat();
UnicodeSegmentation::split_word_bound_indices(&previous_string as &str)
UnicodeSegmentation::split_word_bound_indices(previous_string as &str)
.filter(|(_, word)| !word.trim_start().is_empty())
.next_back()
.map(|(i, previous_word)| {
@ -58,9 +58,8 @@ impl Value {
pub fn next_end_of_word(&self, index: usize) -> usize {
let next_string = &self.graphemes[index..].concat();
UnicodeSegmentation::split_word_bound_indices(&next_string as &str)
.filter(|(_, word)| !word.trim_start().is_empty())
.next()
UnicodeSegmentation::split_word_bound_indices(next_string as &str)
.find(|(_, word)| !word.trim_start().is_empty())
.map(|(i, next_word)| {
index
+ UnicodeSegmentation::graphemes(next_word, true).count()

View file

@ -162,7 +162,10 @@ where
.horizontal_alignment(self.text_alignment)
.font(self.font.clone())
.width(self.width)
.size(self.text_size.unwrap_or(renderer.default_size())),
.size(
self.text_size
.unwrap_or_else(|| renderer.default_size()),
),
);
}
@ -239,7 +242,7 @@ where
renderer,
style,
label_layout,
&label,
label,
self.text_size,
self.font.clone(),
Default::default(),