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

1
clippy.toml Normal file
View file

@ -0,0 +1 @@
too-many-arguments-threshold = 20

View file

@ -183,11 +183,7 @@ where
let mapper = self.mapper; let mapper = self.mapper;
Box::pin( Box::pin(self.recipe.stream(input).map(mapper))
self.recipe
.stream(input)
.map(move |element| mapper(element)),
)
} }
} }

View file

@ -127,7 +127,7 @@ where
futures.push(Box::pin(future)); futures.push(Box::pin(future));
} }
self.subscriptions.retain(|id, _| alive.contains(&id)); self.subscriptions.retain(|id, _| alive.contains(id));
futures futures
} }

View file

@ -70,7 +70,7 @@ impl Shader {
unsafe { unsafe {
let shader = gl.create_shader(stage).expect("Cannot create shader"); let shader = gl.create_shader(stage).expect("Cannot create shader");
gl.shader_source(shader, &content); gl.shader_source(shader, content);
gl.compile_shader(shader); gl.compile_shader(shader);
if !gl.get_shader_compile_status(shader) { if !gl.get_shader_compile_status(shader) {

View file

@ -110,10 +110,8 @@ impl Pipeline {
bounds: Rectangle<u32>, bounds: Rectangle<u32>,
) { ) {
// TODO: Remove this allocation (probably by changing the shader and removing the need of two `position`) // TODO: Remove this allocation (probably by changing the shader and removing the need of two `position`)
let vertices: Vec<Vertex> = instances let vertices: Vec<Vertex> =
.iter() instances.iter().flat_map(Vertex::from_quad).collect();
.flat_map(|quad| Vertex::from_quad(quad))
.collect();
// TODO: Remove this allocation (or allocate only when needed) // TODO: Remove this allocation (or allocate only when needed)
let indices: Vec<i32> = (0..instances.len().min(MAX_QUADS) as i32) let indices: Vec<i32> = (0..instances.len().min(MAX_QUADS) as i32)
@ -187,13 +185,13 @@ impl Pipeline {
gl.buffer_sub_data_u8_slice( gl.buffer_sub_data_u8_slice(
glow::ARRAY_BUFFER, glow::ARRAY_BUFFER,
0, 0,
bytemuck::cast_slice(&vertices), bytemuck::cast_slice(vertices),
); );
gl.buffer_sub_data_u8_slice( gl.buffer_sub_data_u8_slice(
glow::ELEMENT_ARRAY_BUFFER, glow::ELEMENT_ARRAY_BUFFER,
0, 0,
bytemuck::cast_slice(&indices), bytemuck::cast_slice(indices),
); );
gl.draw_elements( gl.draw_elements(

View file

@ -154,7 +154,7 @@ impl Pipeline {
gl.buffer_sub_data_u8_slice( gl.buffer_sub_data_u8_slice(
glow::ARRAY_BUFFER, glow::ARRAY_BUFFER,
0, 0,
bytemuck::cast_slice(&instances), bytemuck::cast_slice(instances),
); );
gl.draw_arrays_instanced( gl.draw_arrays_instanced(

View file

@ -54,7 +54,7 @@ impl Pipeline {
#[cfg(target_arch = "wasm32")] #[cfg(target_arch = "wasm32")]
let draw_brush_builder = draw_brush_builder.draw_cache_align_4x4(true); let draw_brush_builder = draw_brush_builder.draw_cache_align_4x4(true);
let draw_brush = draw_brush_builder.build(&gl); let draw_brush = draw_brush_builder.build(gl);
let measure_brush = let measure_brush =
glyph_brush::GlyphBrushBuilder::using_font(font).build(); glyph_brush::GlyphBrushBuilder::using_font(font).build();
@ -180,7 +180,8 @@ impl Pipeline {
} }
b_count += utf8_len; b_count += utf8_len;
} }
return byte_index;
byte_index
}; };
if !nearest_only { if !nearest_only {

View file

@ -202,7 +202,7 @@ impl<'a> Layer<'a> {
Self::process_primitive( Self::process_primitive(
layers, layers,
translation + *new_translation, translation + *new_translation,
&content, content,
current_layer, current_layer,
); );
} }
@ -210,7 +210,7 @@ impl<'a> Layer<'a> {
Self::process_primitive( Self::process_primitive(
layers, layers,
translation, translation,
&cache, cache,
current_layer, current_layer,
); );
} }

View file

@ -74,7 +74,7 @@ impl Path {
pub(super) fn dashed(path: &Path, line_dash: LineDash<'_>) -> Path { pub(super) fn dashed(path: &Path, line_dash: LineDash<'_>) -> Path {
Path::new(|builder| { Path::new(|builder| {
let segments_odd = (line_dash.segments.len() % 2 == 1).then(|| { let segments_odd = (line_dash.segments.len() % 2 == 1).then(|| {
[&line_dash.segments[..], &line_dash.segments[..]].concat() [line_dash.segments, line_dash.segments].concat()
}); });
let mut draw_line = false; let mut draw_line = false;
@ -103,8 +103,7 @@ pub(super) fn dashed(path: &Path, line_dash: LineDash<'_>) -> Path {
}, },
index: line_dash.offset, index: line_dash.offset,
intervals: segments_odd intervals: segments_odd
.as_ref() .as_deref()
.map(Vec::as_slice)
.unwrap_or(line_dash.segments), .unwrap_or(line_dash.segments),
}, },
); );

View file

@ -53,7 +53,7 @@ impl Builder {
let _ = self.raw.line_to(a); let _ = self.raw.line_to(a);
} }
let _ = self.raw.arc_to( self.raw.arc_to(
math::Vector::new(radius, radius), math::Vector::new(radius, radius),
math::Angle::radians(0.0), math::Angle::radians(0.0),
path::ArcFlags::default(), path::ArcFlags::default(),

View file

@ -67,10 +67,7 @@ where
let side_length = (self.state.width + 2 * QUIET_ZONE) as f32 let side_length = (self.state.width + 2 * QUIET_ZONE) as f32
* f32::from(self.cell_size); * f32::from(self.cell_size);
layout::Node::new(Size::new( layout::Node::new(Size::new(side_length, side_length))
f32::from(side_length),
f32::from(side_length),
))
} }
fn draw( fn draw(

View file

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

View file

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

View file

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

View file

@ -430,7 +430,7 @@ where
overlay overlay
.as_ref() .as_ref()
.and_then(|layout| { .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( let overlay_interaction = overlay.mouse_interaction(
Layout::new(layout), Layout::new(layout),
cursor_position, cursor_position,

View file

@ -158,7 +158,10 @@ where
Text::new(&self.label) Text::new(&self.label)
.font(self.font.clone()) .font(self.font.clone())
.width(self.width) .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) .layout(renderer, limits)
} }

View file

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

View file

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

View file

@ -66,6 +66,11 @@ impl<T> State<T> {
self.panes.len() 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. /// Returns the internal state of the given [`Pane`], if it exists.
pub fn get(&self, pane: &Pane) -> Option<&T> { pub fn get(&self, pane: &Pane) -> Option<&T> {
self.panes.get(pane) self.panes.get(pane)

View file

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

View file

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

View file

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

View file

@ -303,7 +303,7 @@ pub fn draw<T, R>(
HandleShape::Rectangle { HandleShape::Rectangle {
width, width,
border_radius, border_radius,
} => (f32::from(width), f32::from(bounds.height), border_radius), } => (f32::from(width), bounds.height, border_radius),
}; };
let value = value.into() as f32; let value = value.into() as f32;
@ -447,7 +447,7 @@ where
_viewport: &Rectangle, _viewport: &Rectangle,
_renderer: &Renderer, _renderer: &Renderer,
) -> mouse::Interaction { ) -> 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 { ) -> layout::Node {
let limits = limits.width(self.width).height(self.height); 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(); let bounds = limits.max();
@ -205,7 +205,7 @@ pub fn draw<Renderer>(
renderer.fill_text(crate::text::Text { renderer.fill_text(crate::text::Text {
content, 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 }, bounds: Rectangle { x, y, ..bounds },
color: appearance.color.unwrap_or(style.text_color), color: appearance.color.unwrap_or(style.text_color),
font, font,

View file

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

View file

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

View file

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

View file

@ -162,7 +162,10 @@ where
.horizontal_alignment(self.text_alignment) .horizontal_alignment(self.text_alignment)
.font(self.font.clone()) .font(self.font.clone())
.width(self.width) .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, renderer,
style, style,
label_layout, label_layout,
&label, label,
self.text_size, self.text_size,
self.font.clone(), self.font.clone(),
Default::default(), Default::default(),

View file

@ -146,7 +146,7 @@ where
content: impl Into<Element<'a, Message, Renderer>>, content: impl Into<Element<'a, Message, Renderer>>,
) -> Self { ) -> Self {
let element = content.into(); let element = content.into();
let _ = state.diff(&element); state.diff(&element);
Self { state, element } Self { state, element }
} }

View file

@ -143,7 +143,7 @@ where
self.padding, self.padding,
self.text_size, self.text_size,
&self.font, &self.font,
self.placeholder.as_ref().map(String::as_str), self.placeholder.as_deref(),
&self.options, &self.options,
) )
} }
@ -199,7 +199,7 @@ where
self.padding, self.padding,
self.text_size, self.text_size,
&self.font, &self.font,
self.placeholder.as_ref().map(String::as_str), self.placeholder.as_deref(),
self.selected.as_ref(), self.selected.as_ref(),
self.style, self.style,
) )

View file

@ -93,7 +93,7 @@ impl Backend {
&layer, &layer,
staging_belt, staging_belt,
encoder, encoder,
&frame, frame,
target_size.width, target_size.width,
target_size.height, target_size.height,
); );

View file

@ -236,7 +236,7 @@ impl Pipeline {
entries: &[wgpu::BindGroupEntry { entries: &[wgpu::BindGroupEntry {
binding: 0, binding: 0,
resource: wgpu::BindingResource::TextureView( resource: wgpu::BindingResource::TextureView(
&texture_atlas.view(), texture_atlas.view(),
), ),
}], }],
}); });
@ -264,7 +264,7 @@ impl Pipeline {
#[cfg(feature = "image_rs")] #[cfg(feature = "image_rs")]
pub fn dimensions(&self, handle: &image::Handle) -> (u32, u32) { pub fn dimensions(&self, handle: &image::Handle) -> (u32, u32) {
let mut cache = self.raster_cache.borrow_mut(); let mut cache = self.raster_cache.borrow_mut();
let memory = cache.load(&handle); let memory = cache.load(handle);
memory.dimensions() memory.dimensions()
} }
@ -272,7 +272,7 @@ impl Pipeline {
#[cfg(feature = "svg")] #[cfg(feature = "svg")]
pub fn viewport_dimensions(&self, handle: &svg::Handle) -> (u32, u32) { pub fn viewport_dimensions(&self, handle: &svg::Handle) -> (u32, u32) {
let mut cache = self.vector_cache.borrow_mut(); let mut cache = self.vector_cache.borrow_mut();
let svg = cache.load(&handle); let svg = cache.load(handle);
svg.viewport_dimensions() svg.viewport_dimensions()
} }
@ -358,7 +358,7 @@ impl Pipeline {
entries: &[wgpu::BindGroupEntry { entries: &[wgpu::BindGroupEntry {
binding: 0, binding: 0,
resource: wgpu::BindingResource::TextureView( resource: wgpu::BindingResource::TextureView(
&self.texture_atlas.view(), self.texture_atlas.view(),
), ),
}], }],
}); });

View file

@ -118,7 +118,7 @@ impl Atlas {
height, height,
padding, padding,
0, 0,
&allocation, allocation,
encoder, encoder,
); );
} }

View file

@ -9,9 +9,6 @@ pub enum Layer {
impl Layer { impl Layer {
pub fn is_empty(&self) -> bool { pub fn is_empty(&self) -> bool {
match self { matches!(self, Layer::Empty)
Layer::Empty => true,
_ => false,
}
} }
} }

View file

@ -59,7 +59,7 @@ impl Cache {
} }
} }
image::Data::Bytes(bytes) => { image::Data::Bytes(bytes) => {
if let Ok(image) = image_rs::load_from_memory(&bytes) { if let Ok(image) = image_rs::load_from_memory(bytes) {
let operation = let operation =
Operation::from_exif(&mut std::io::Cursor::new(bytes)) Operation::from_exif(&mut std::io::Cursor::new(bytes))
.ok() .ok()

View file

@ -60,7 +60,7 @@ impl Cache {
} }
svg::Data::Bytes(bytes) => { svg::Data::Bytes(bytes) => {
match usvg::Tree::from_data( match usvg::Tree::from_data(
&bytes, bytes,
&usvg::Options::default().to_ref(), &usvg::Options::default().to_ref(),
) { ) {
Ok(tree) => Svg::Loaded(tree), Ok(tree) => Svg::Loaded(tree),
@ -112,7 +112,7 @@ impl Cache {
// It would be cool to be able to smooth resize the `svg` example. // It would be cool to be able to smooth resize the `svg` example.
let mut img = tiny_skia::Pixmap::new(width, height)?; let mut img = tiny_skia::Pixmap::new(width, height)?;
let _ = resvg::render( resvg::render(
tree, tree,
if width > height { if width > height {
usvg::FitTo::Width(width) usvg::FitTo::Width(width)

View file

@ -188,7 +188,8 @@ impl Pipeline {
} }
b_count += utf8_len; b_count += utf8_len;
} }
return byte_index;
byte_index
}; };
if !nearest_only { if !nearest_only {

View file

@ -173,9 +173,7 @@ impl Pipeline {
}, },
depth_stencil: None, depth_stencil: None,
multisample: wgpu::MultisampleState { multisample: wgpu::MultisampleState {
count: u32::from( count: antialiasing.map(|a| a.sample_count()).unwrap_or(1),
antialiasing.map(|a| a.sample_count()).unwrap_or(1),
),
mask: !0, mask: !0,
alpha_to_coverage_enabled: false, alpha_to_coverage_enabled: false,
}, },
@ -272,47 +270,43 @@ impl Pipeline {
let vertices = bytemuck::cast_slice(&mesh.buffers.vertices); let vertices = bytemuck::cast_slice(&mesh.buffers.vertices);
let indices = bytemuck::cast_slice(&mesh.buffers.indices); let indices = bytemuck::cast_slice(&mesh.buffers.indices);
match ( if let (Some(vertices_size), Some(indices_size)) = (
wgpu::BufferSize::new(vertices.len() as u64), wgpu::BufferSize::new(vertices.len() as u64),
wgpu::BufferSize::new(indices.len() as u64), wgpu::BufferSize::new(indices.len() as u64),
) { ) {
(Some(vertices_size), Some(indices_size)) => { {
{ let mut vertex_buffer = staging_belt.write_buffer(
let mut vertex_buffer = staging_belt.write_buffer( encoder,
encoder, &self.vertex_buffer.raw,
&self.vertex_buffer.raw, (std::mem::size_of::<Vertex2D>() * last_vertex) as u64,
(std::mem::size_of::<Vertex2D>() * last_vertex) vertices_size,
as u64, device,
vertices_size, );
device,
);
vertex_buffer.copy_from_slice(vertices); vertex_buffer.copy_from_slice(vertices);
}
{
let mut index_buffer = staging_belt.write_buffer(
encoder,
&self.index_buffer.raw,
(std::mem::size_of::<u32>() * last_index) as u64,
indices_size,
device,
);
index_buffer.copy_from_slice(indices);
}
uniforms.push(transform);
offsets.push((
last_vertex as u64,
last_index as u64,
mesh.buffers.indices.len(),
));
last_vertex += mesh.buffers.vertices.len();
last_index += mesh.buffers.indices.len();
} }
_ => {}
{
let mut index_buffer = staging_belt.write_buffer(
encoder,
&self.index_buffer.raw,
(std::mem::size_of::<u32>() * last_index) as u64,
indices_size,
device,
);
index_buffer.copy_from_slice(indices);
}
uniforms.push(transform);
offsets.push((
last_vertex as u64,
last_index as u64,
mesh.buffers.indices.len(),
));
last_vertex += mesh.buffers.vertices.len();
last_index += mesh.buffers.indices.len();
} }
} }

View file

@ -134,7 +134,7 @@ impl Blit {
match &mut self.targets { match &mut self.targets {
None => { None => {
self.targets = Some(Targets::new( self.targets = Some(Targets::new(
&device, device,
self.format, self.format,
&self.texture_layout, &self.texture_layout,
self.sample_count, self.sample_count,
@ -145,7 +145,7 @@ impl Blit {
Some(targets) => { Some(targets) => {
if targets.width != width || targets.height != height { if targets.width != width || targets.height != height {
self.targets = Some(Targets::new( self.targets = Some(Targets::new(
&device, device,
self.format, self.format,
&self.texture_layout, &self.texture_layout,
self.sample_count, self.sample_count,

View file

@ -225,7 +225,7 @@ impl<Theme> iced_graphics::window::Compositor for Compositor<Theme> {
renderer.with_primitives(|backend, primitives| { renderer.with_primitives(|backend, primitives| {
backend.present( backend.present(
&mut self.device, &self.device,
&mut self.staging_belt, &mut self.staging_belt,
&mut encoder, &mut encoder,
view, view,

View file

@ -647,7 +647,7 @@ mod platform {
{ {
use winit::platform::run_return::EventLoopExtRunReturn; use winit::platform::run_return::EventLoopExtRunReturn;
let _ = event_loop.run_return(event_handler); event_loop.run_return(event_handler);
Ok(()) Ok(())
} }

View file

@ -485,10 +485,10 @@ pub fn key_code(
// As defined in: http://www.unicode.org/faq/private_use.html // As defined in: http://www.unicode.org/faq/private_use.html
pub(crate) fn is_private_use_character(c: char) -> bool { pub(crate) fn is_private_use_character(c: char) -> bool {
match c { matches!(
c,
'\u{E000}'..='\u{F8FF}' '\u{E000}'..='\u{F8FF}'
| '\u{F0000}'..='\u{FFFFD}' | '\u{F0000}'..='\u{FFFFD}'
| '\u{100000}'..='\u{10FFFD}' => true, | '\u{100000}'..='\u{10FFFD}'
_ => false, )
}
} }

View file

@ -24,7 +24,7 @@ pub(crate) fn information(
let memory_used = sysinfo::get_current_pid() let memory_used = sysinfo::get_current_pid()
.and_then(|pid| system.process(pid).ok_or("Process not found")) .and_then(|pid| system.process(pid).ok_or("Process not found"))
.and_then(|process| Ok(process.memory())) .map(|process| process.memory())
.ok(); .ok();
Information { Information {