diff --git a/crates/fj-app/src/path.rs b/crates/fj-app/src/path.rs index 5d0a7c02e..b68964c44 100644 --- a/crates/fj-app/src/path.rs +++ b/crates/fj-app/src/path.rs @@ -71,8 +71,8 @@ enum ModelPathSource { impl ModelPathSource { fn path(&self) -> &Path { match self { - ModelPathSource::Args(path) => path, - ModelPathSource::Config(path) => path, + Self::Args(path) => path, + Self::Config(path) => path, } } } @@ -99,10 +99,10 @@ fn load_error_context_inner( )?; match model_path { ModelPathSource::Args(_) => { - write!(error, "\n- Passed via command-line argument")? + write!(error, "\n- Passed via command-line argument")?; } ModelPathSource::Config(_) => { - write!(error, "\n- Specified as default model in configuration")? + write!(error, "\n- Specified as default model in configuration")?; } } write!(error, "\n- Path of model: {}", path.display())?; diff --git a/crates/fj-export/src/lib.rs b/crates/fj-export/src/lib.rs index b914c98b5..08ebc0cfa 100644 --- a/crates/fj-export/src/lib.rs +++ b/crates/fj-export/src/lib.rs @@ -43,7 +43,7 @@ pub fn export(mesh: &Mesh>, path: &Path) -> Result<(), Error> { } fn export_3mf(mesh: &Mesh>, path: &Path) -> Result<(), Error> { - let vertices = mesh.vertices().map(|vertex| vertex.into()).collect(); + let vertices = mesh.vertices().map(Into::into).collect(); let indices: Vec<_> = mesh.indices().collect(); let triangles = indices diff --git a/crates/fj-host/src/evaluator.rs b/crates/fj-host/src/evaluator.rs index eb84b0c15..307fa95f3 100644 --- a/crates/fj-host/src/evaluator.rs +++ b/crates/fj-host/src/evaluator.rs @@ -17,7 +17,7 @@ impl Evaluator { let (trigger_tx, trigger_rx) = crossbeam_channel::bounded(0); thread::spawn(move || { - while let Ok(TriggerEvaluation) = trigger_rx.recv() { + while matches!(trigger_rx.recv(), Ok(TriggerEvaluation)) { if let Err(SendError(_)) = event_tx.send(ModelEvent::ChangeDetected) { @@ -49,8 +49,8 @@ impl Evaluator { }); Self { - event_rx, trigger_tx, + event_rx, } } diff --git a/crates/fj-host/src/host.rs b/crates/fj-host/src/host.rs index 9e1c20219..d681347a0 100644 --- a/crates/fj-host/src/host.rs +++ b/crates/fj-host/src/host.rs @@ -16,7 +16,7 @@ impl Host { pub fn from_model(model: Model) -> Result { let watch_path = model.watch_path(); let evaluator = Evaluator::from_model(model); - let watcher = Watcher::watch_model(&watch_path, &evaluator)?; + let watcher = Watcher::watch_model(watch_path, &evaluator)?; Ok(Self { evaluator, diff --git a/crates/fj-host/src/model.rs b/crates/fj-host/src/model.rs index 43213dd0f..0e752215e 100644 --- a/crates/fj-host/src/model.rs +++ b/crates/fj-host/src/model.rs @@ -204,7 +204,7 @@ impl<'a> fj::models::Host for Host<'a> { impl<'a> fj::models::Context for Host<'a> { fn get_argument(&self, name: &str) -> Option<&str> { - self.args.get(name).map(|s| s.as_str()) + self.args.get(name).map(String::as_str) } } diff --git a/crates/fj-host/src/platform.rs b/crates/fj-host/src/platform.rs index 9ef2f2393..47f6ead5f 100644 --- a/crates/fj-host/src/platform.rs +++ b/crates/fj-host/src/platform.rs @@ -14,19 +14,19 @@ struct Unix; impl Platform for Windows { fn model_lib_file_name(&self, name: &str) -> String { - format!("{}.dll", name) + format!("{name}.dll") } } impl Platform for Macos { fn model_lib_file_name(&self, name: &str) -> String { - format!("lib{}.dylib", name) + format!("lib{name}.dylib") } } impl Platform for Unix { fn model_lib_file_name(&self, name: &str) -> String { - format!("lib{}.so", name) + format!("lib{name}.so") } } diff --git a/crates/fj-host/src/watcher.rs b/crates/fj-host/src/watcher.rs index 9d0374841..4f56ff4bb 100644 --- a/crates/fj-host/src/watcher.rs +++ b/crates/fj-host/src/watcher.rs @@ -29,16 +29,10 @@ impl Watcher { // Various acceptable ModifyKind kinds. Varies across platforms // (e.g. MacOs vs. Windows10) if let notify::EventKind::Modify( - notify::event::ModifyKind::Any, - ) - | notify::EventKind::Modify( - notify::event::ModifyKind::Data( - notify::event::DataChange::Any, - ), - ) - | notify::EventKind::Modify( - notify::event::ModifyKind::Data( - notify::event::DataChange::Content, + notify::event::ModifyKind::Any + | notify::event::ModifyKind::Data( + notify::event::DataChange::Any + | notify::event::DataChange::Content, ), ) = event.kind { @@ -86,7 +80,7 @@ impl Watcher { thread::spawn(move || { watch_tx_2 .send(TriggerEvaluation) - .expect("Channel is disconnected") + .expect("Channel is disconnected"); }); Ok(Self { diff --git a/crates/fj-interop/src/mesh.rs b/crates/fj-interop/src/mesh.rs index 006782997..da17eebd0 100644 --- a/crates/fj-interop/src/mesh.rs +++ b/crates/fj-interop/src/mesh.rs @@ -96,10 +96,10 @@ impl Mesh> { impl Default for Mesh { fn default() -> Self { Self { - vertices: Default::default(), - indices: Default::default(), - indices_by_vertex: Default::default(), - triangles: Default::default(), + vertices: Vec::default(), + indices: Vec::default(), + indices_by_vertex: HashMap::default(), + triangles: Vec::default(), } } } diff --git a/crates/fj-kernel/src/algorithms/intersect/curve_face.rs b/crates/fj-kernel/src/algorithms/intersect/curve_face.rs index dfe0cb790..346ae1f61 100644 --- a/crates/fj-kernel/src/algorithms/intersect/curve_face.rs +++ b/crates/fj-kernel/src/algorithms/intersect/curve_face.rs @@ -58,7 +58,7 @@ impl CurveFaceIntersection { .map(|&[start, end]| CurveFaceIntersectionInterval { start, end }) .collect(); - CurveFaceIntersection { intervals } + Self { intervals } } /// Merge this intersection list with another @@ -143,7 +143,7 @@ where { fn from(interval: [P; 2]) -> Self { let [start, end] = interval.map(Into::into); - CurveFaceIntersectionInterval { start, end } + Self { start, end } } } diff --git a/crates/fj-kernel/src/algorithms/sweep/vertex.rs b/crates/fj-kernel/src/algorithms/sweep/vertex.rs index 3e27dece8..21220325c 100644 --- a/crates/fj-kernel/src/algorithms/sweep/vertex.rs +++ b/crates/fj-kernel/src/algorithms/sweep/vertex.rs @@ -125,7 +125,7 @@ impl Sweep for (Handle, Handle) { } impl Sweep for Handle { - type Swept = (Handle, [Handle; 2]); + type Swept = (Handle, [Self; 2]); fn sweep_with_cache( self, diff --git a/crates/fj-kernel/src/algorithms/transform/face.rs b/crates/fj-kernel/src/algorithms/transform/face.rs index 5d600f7c1..86a9f2b8e 100644 --- a/crates/fj-kernel/src/algorithms/transform/face.rs +++ b/crates/fj-kernel/src/algorithms/transform/face.rs @@ -36,7 +36,7 @@ impl TransformObject for FaceSet { objects: &mut Service, cache: &mut TransformCache, ) -> Self { - let mut faces = FaceSet::new(); + let mut faces = Self::new(); faces.extend( self.into_iter().map(|face| { face.transform_with_cache(transform, objects, cache) diff --git a/crates/fj-kernel/src/algorithms/transform/shell.rs b/crates/fj-kernel/src/algorithms/transform/shell.rs index 22994b13d..705e2785b 100644 --- a/crates/fj-kernel/src/algorithms/transform/shell.rs +++ b/crates/fj-kernel/src/algorithms/transform/shell.rs @@ -19,6 +19,6 @@ impl TransformObject for Shell { face.transform_with_cache(transform, objects, cache) }); - Shell::new(faces) + Self::new(faces) } } diff --git a/crates/fj-kernel/src/algorithms/transform/sketch.rs b/crates/fj-kernel/src/algorithms/transform/sketch.rs index 7249dd6a1..5aca6243c 100644 --- a/crates/fj-kernel/src/algorithms/transform/sketch.rs +++ b/crates/fj-kernel/src/algorithms/transform/sketch.rs @@ -19,6 +19,6 @@ impl TransformObject for Sketch { face.transform_with_cache(transform, objects, cache) }); - Sketch::new(faces) + Self::new(faces) } } diff --git a/crates/fj-kernel/src/algorithms/transform/solid.rs b/crates/fj-kernel/src/algorithms/transform/solid.rs index 92b8ab869..f0179dad5 100644 --- a/crates/fj-kernel/src/algorithms/transform/solid.rs +++ b/crates/fj-kernel/src/algorithms/transform/solid.rs @@ -19,6 +19,6 @@ impl TransformObject for Solid { .cloned() .map(|shell| shell.transform_with_cache(transform, objects, cache)); - Solid::new(shells) + Self::new(shells) } } diff --git a/crates/fj-kernel/src/algorithms/triangulate/polygon.rs b/crates/fj-kernel/src/algorithms/triangulate/polygon.rs index fa733330e..4dea94902 100644 --- a/crates/fj-kernel/src/algorithms/triangulate/polygon.rs +++ b/crates/fj-kernel/src/algorithms/triangulate/polygon.rs @@ -5,6 +5,7 @@ use crate::algorithms::intersect::{ ray_segment::RaySegmentIntersection, HorizontalRayToTheRight, Intersect, }; +#[derive(Default)] pub struct Polygon { exterior: PolyChain<2>, interiors: Vec>, @@ -13,10 +14,7 @@ pub struct Polygon { impl Polygon { /// Construct an instance of `Polygon` pub fn new() -> Self { - Self { - exterior: PolyChain::new(), - interiors: Vec::new(), - } + Self::default() } pub fn with_exterior(mut self, exterior: impl Into>) -> Self { diff --git a/crates/fj-kernel/src/builder/vertex.rs b/crates/fj-kernel/src/builder/vertex.rs index 9c3266b00..7fac0df5d 100644 --- a/crates/fj-kernel/src/builder/vertex.rs +++ b/crates/fj-kernel/src/builder/vertex.rs @@ -76,7 +76,7 @@ impl GlobalVertexBuilder for PartialGlobalVertex { surface: &SurfaceGeometry, position: impl Into>, ) -> Self { - PartialGlobalVertex { + Self { position: Some(surface.point_from_surface_coords(position)), } } diff --git a/crates/fj-kernel/src/geometry/path.rs b/crates/fj-kernel/src/geometry/path.rs index a4b7a528b..666628254 100644 --- a/crates/fj-kernel/src/geometry/path.rs +++ b/crates/fj-kernel/src/geometry/path.rs @@ -39,10 +39,7 @@ impl SurfacePath { pub fn circle_from_radius(radius: impl Into) -> Self { let radius = radius.into(); - SurfacePath::Circle(Circle::from_center_and_radius( - Point::origin(), - radius, - )) + Self::Circle(Circle::from_center_and_radius(Point::origin(), radius)) } /// Construct a line from two points @@ -101,10 +98,7 @@ impl GlobalPath { pub fn circle_from_radius(radius: impl Into) -> Self { let radius = radius.into(); - GlobalPath::Circle(Circle::from_center_and_radius( - Point::origin(), - radius, - )) + Self::Circle(Circle::from_center_and_radius(Point::origin(), radius)) } /// Construct a line from two points diff --git a/crates/fj-kernel/src/iter.rs b/crates/fj-kernel/src/iter.rs index d7d8974f7..d870028fe 100644 --- a/crates/fj-kernel/src/iter.rs +++ b/crates/fj-kernel/src/iter.rs @@ -299,7 +299,7 @@ where fn referenced_objects(&'r self) -> Vec<&'r dyn ObjectIters> { let mut objects = Vec::new(); - for object in self.into_iter() { + for object in self { objects.push(object as &dyn ObjectIters); } diff --git a/crates/fj-kernel/src/objects/full/edge.rs b/crates/fj-kernel/src/objects/full/edge.rs index 2e8686f4a..74ce50f7b 100644 --- a/crates/fj-kernel/src/objects/full/edge.rs +++ b/crates/fj-kernel/src/objects/full/edge.rs @@ -74,7 +74,7 @@ impl Get for HalfEdge { impl fmt::Display for HalfEdge { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { let [a, b] = self.vertices().clone().map(|vertex| vertex.position()); - write!(f, "edge from {:?} to {:?}", a, b)?; + write!(f, "edge from {a:?} to {b:?}")?; write!(f, " on {:?}", self.curve().global_form())?; Ok(()) diff --git a/crates/fj-kernel/src/objects/full/face.rs b/crates/fj-kernel/src/objects/full/face.rs index 4e4bc41f5..95e9d6b87 100644 --- a/crates/fj-kernel/src/objects/full/face.rs +++ b/crates/fj-kernel/src/objects/full/face.rs @@ -126,7 +126,7 @@ impl FaceSet { impl Extend> for FaceSet { fn extend>>(&mut self, iter: T) { - self.inner.extend(iter) + self.inner.extend(iter); } } diff --git a/crates/fj-kernel/src/partial/maybe_partial.rs b/crates/fj-kernel/src/partial/maybe_partial.rs index 6d8e370d2..7a9319124 100644 --- a/crates/fj-kernel/src/partial/maybe_partial.rs +++ b/crates/fj-kernel/src/partial/maybe_partial.rs @@ -161,16 +161,16 @@ impl MaybePartial { /// Access the path pub fn path(&self) -> Option { match self { - MaybePartial::Full(full) => Some(full.path()), - MaybePartial::Partial(partial) => partial.path, + Self::Full(full) => Some(full.path()), + Self::Partial(partial) => partial.path, } } /// Access the surface pub fn surface(&self) -> Option> { match self { - MaybePartial::Full(full) => Some(full.surface().clone()), - MaybePartial::Partial(partial) => partial.surface.clone(), + Self::Full(full) => Some(full.surface().clone()), + Self::Partial(partial) => partial.surface.clone(), } } diff --git a/crates/fj-kernel/src/partial/merge.rs b/crates/fj-kernel/src/partial/merge.rs index dac76cf55..f41a59812 100644 --- a/crates/fj-kernel/src/partial/merge.rs +++ b/crates/fj-kernel/src/partial/merge.rs @@ -46,9 +46,10 @@ where } // We know that `self != other`, or we wouldn't have made it here. - if self.is_some() && other.is_some() { - panic!("Can't merge two `Option`s that are both `Some`") - } + assert!( + self.is_none() || other.is_none(), + "Can't merge two `Option`s that are both `Some`" + ); self.xor(other) } diff --git a/crates/fj-kernel/src/partial/objects/vertex.rs b/crates/fj-kernel/src/partial/objects/vertex.rs index 22c2fe6ad..b9d1f7f89 100644 --- a/crates/fj-kernel/src/partial/objects/vertex.rs +++ b/crates/fj-kernel/src/partial/objects/vertex.rs @@ -115,7 +115,7 @@ impl PartialSurfaceVertex { &surface.geometry(), position, ), - ) + ); } let global_form = self.global_form.into_full(objects); diff --git a/crates/fj-kernel/src/services/objects.rs b/crates/fj-kernel/src/services/objects.rs index 9bbd43610..a5defbe26 100644 --- a/crates/fj-kernel/src/services/objects.rs +++ b/crates/fj-kernel/src/services/objects.rs @@ -53,6 +53,6 @@ impl ServiceObjectsExt for Service { { self.execute(InsertObject { object: (handle, object).into(), - }) + }); } } diff --git a/crates/fj-kernel/src/storage/blocks.rs b/crates/fj-kernel/src/storage/blocks.rs index 474b3d002..7a67b5c42 100644 --- a/crates/fj-kernel/src/storage/blocks.rs +++ b/crates/fj-kernel/src/storage/blocks.rs @@ -94,9 +94,7 @@ impl Block { pub fn insert(&mut self, index: ObjectIndex, object: T) { let slot = &mut self.objects[index.0]; - if slot.is_some() { - panic!("Attempting to overwrite object in store") - } + assert!(slot.is_none(), "Attempting to overwrite object in store"); *slot = Some(object); } diff --git a/crates/fj-kernel/src/storage/handle.rs b/crates/fj-kernel/src/storage/handle.rs index f66f932cf..2b33c5e4a 100644 --- a/crates/fj-kernel/src/storage/handle.rs +++ b/crates/fj-kernel/src/storage/handle.rs @@ -108,7 +108,7 @@ where T: Hash, { fn hash(&self, state: &mut H) { - self.deref().hash(state) + self.deref().hash(state); } } @@ -244,7 +244,7 @@ impl Hash for HandleWrapper { return; } - self.0.id().hash(state) + self.0.id().hash(state); } } diff --git a/crates/fj-kernel/src/storage/store.rs b/crates/fj-kernel/src/storage/store.rs index 564a38238..44307f324 100644 --- a/crates/fj-kernel/src/storage/store.rs +++ b/crates/fj-kernel/src/storage/store.rs @@ -179,6 +179,6 @@ mod tests { store.insert(b.clone(), 1); let objects = store.iter().collect::>(); - assert_eq!(objects, [a, b]) + assert_eq!(objects, [a, b]); } } diff --git a/crates/fj-kernel/src/validate/edge.rs b/crates/fj-kernel/src/validate/edge.rs index fff2d900d..85435cc6a 100644 --- a/crates/fj-kernel/src/validate/edge.rs +++ b/crates/fj-kernel/src/validate/edge.rs @@ -117,7 +117,7 @@ impl HalfEdgeValidationError { let front_curve = half_edge.front().curve(); if back_curve.id() != front_curve.id() { - return Err(HalfEdgeValidationError::CurveMismatch { + return Err(Self::CurveMismatch { back_curve: back_curve.clone(), front_curve: front_curve.clone(), }); diff --git a/crates/fj-kernel/src/validate/vertex.rs b/crates/fj-kernel/src/validate/vertex.rs index 352668a27..992a80708 100644 --- a/crates/fj-kernel/src/validate/vertex.rs +++ b/crates/fj-kernel/src/validate/vertex.rs @@ -91,7 +91,7 @@ impl VertexValidationError { let surface_form_surface = vertex.surface_form().surface(); if curve_surface.id() != surface_form_surface.id() { - return Err(VertexValidationError::SurfaceMismatch { + return Err(Self::SurfaceMismatch { curve_surface: curve_surface.clone(), surface_form_surface: surface_form_surface.clone(), }); @@ -113,7 +113,7 @@ impl VertexValidationError { let distance = curve_position_as_surface.distance_to(&surface_position); if distance > config.identical_max_distance { - return Err(VertexValidationError::PositionMismatch { + return Err(Self::PositionMismatch { vertex: vertex.clone(), surface_vertex: vertex.surface_form().clone_object(), curve_position_as_surface, diff --git a/crates/fj-math/src/aabb.rs b/crates/fj-math/src/aabb.rs index 001cc9a6e..7c5b9e496 100644 --- a/crates/fj-math/src/aabb.rs +++ b/crates/fj-math/src/aabb.rs @@ -101,7 +101,7 @@ impl Aabb<3> { /// Access the vertices of the AABB pub fn vertices(&self) -> [Point<3>; 8] { - self.to_parry().vertices().map(|vertex| vertex.into()) + self.to_parry().vertices().map(Into::into) } /// Compute the center point of the AABB diff --git a/crates/fj-math/src/circle.rs b/crates/fj-math/src/circle.rs index 9190650a6..303e8fdd0 100644 --- a/crates/fj-math/src/circle.rs +++ b/crates/fj-math/src/circle.rs @@ -67,7 +67,7 @@ impl Circle { a[0] = radius; b[1] = radius; - Circle::new(center, a, b) + Self::new(center, a, b) } /// Access the center point of the circle diff --git a/crates/fj-math/src/line.rs b/crates/fj-math/src/line.rs index 30e501d9f..bec71a29c 100644 --- a/crates/fj-math/src/line.rs +++ b/crates/fj-math/src/line.rs @@ -21,12 +21,10 @@ impl Line { origin: Point, direction: Vector, ) -> Self { - if direction.magnitude() == Scalar::ZERO { - panic!( - "Can't construct `Line`. Direction is zero: {:?}", - direction - ); - } + assert!( + direction.magnitude() != Scalar::ZERO, + "Can't construct `Line`. Direction is zero: {direction:?}" + ); Self { origin, direction } } diff --git a/crates/fj-math/src/point.rs b/crates/fj-math/src/point.rs index e6164d4bb..d52997974 100644 --- a/crates/fj-math/src/point.rs +++ b/crates/fj-math/src/point.rs @@ -60,7 +60,7 @@ impl Point { } /// Gives the distance between two points. - pub fn distance_to(&self, other: &Point) -> Scalar { + pub fn distance_to(&self, other: &Self) -> Scalar { (self.coords - other.coords).magnitude() } } diff --git a/crates/fj-math/src/scalar.rs b/crates/fj-math/src/scalar.rs index 3d6a0ea1f..88fc2ba99 100644 --- a/crates/fj-math/src/scalar.rs +++ b/crates/fj-math/src/scalar.rs @@ -82,7 +82,7 @@ impl Scalar { /// Indicate whether the scalar is zero pub fn is_zero(self) -> bool { - self == Scalar::ZERO + self == Self::ZERO } /// The sign of the scalar @@ -182,7 +182,7 @@ impl Hash for Scalar { impl From for Scalar { fn from(scalar: f32) -> Self { - Self::from_f64(scalar as f64) + Self::from_f64(scalar.into()) } } @@ -206,7 +206,7 @@ impl ops::Neg for Scalar { } } -impl> ops::Add for Scalar { +impl> ops::Add for Scalar { type Output = Self; fn add(self, rhs: T) -> Self::Output { @@ -214,7 +214,7 @@ impl> ops::Add for Scalar { } } -impl> ops::Sub for Scalar { +impl> ops::Sub for Scalar { type Output = Self; fn sub(self, rhs: T) -> Self::Output { @@ -222,7 +222,7 @@ impl> ops::Sub for Scalar { } } -impl> ops::Mul for Scalar { +impl> ops::Mul for Scalar { type Output = Self; fn mul(self, rhs: T) -> Self::Output { @@ -230,7 +230,7 @@ impl> ops::Mul for Scalar { } } -impl> ops::Div for Scalar { +impl> ops::Div for Scalar { type Output = Self; fn div(self, rhs: T) -> Self::Output { @@ -238,7 +238,7 @@ impl> ops::Div for Scalar { } } -impl> ops::Rem for Scalar { +impl> ops::Rem for Scalar { type Output = Self; fn rem(self, rhs: T) -> Self::Output { @@ -246,35 +246,35 @@ impl> ops::Rem for Scalar { } } -impl> ops::AddAssign for Scalar { +impl> ops::AddAssign for Scalar { fn add_assign(&mut self, rhs: T) { self.0.add_assign(rhs.into().0); *self = self.0.into(); } } -impl> ops::SubAssign for Scalar { +impl> ops::SubAssign for Scalar { fn sub_assign(&mut self, rhs: T) { self.0.sub_assign(rhs.into().0); *self = self.0.into(); } } -impl> ops::MulAssign for Scalar { +impl> ops::MulAssign for Scalar { fn mul_assign(&mut self, rhs: T) { self.0.mul_assign(rhs.into().0); *self = self.0.into(); } } -impl> ops::DivAssign for Scalar { +impl> ops::DivAssign for Scalar { fn div_assign(&mut self, rhs: T) { self.0.div_assign(rhs.into().0); *self = self.0.into(); } } -impl> ops::RemAssign for Scalar { +impl> ops::RemAssign for Scalar { fn rem_assign(&mut self, rhs: T) { self.0.rem_assign(rhs.into().0); *self = self.0.into(); @@ -608,9 +608,9 @@ impl Sign { /// Convert this sign back to a scalar pub fn to_scalar(self) -> Scalar { match self { - Sign::Negative => -Scalar::ONE, - Sign::Positive => Scalar::ONE, - Sign::Zero => Scalar::ZERO, + Self::Negative => -Scalar::ONE, + Self::Positive => Scalar::ONE, + Self::Zero => Scalar::ZERO, } } } diff --git a/crates/fj-math/src/transform.rs b/crates/fj-math/src/transform.rs index f607fef1b..3fcb4d8fb 100644 --- a/crates/fj-math/src/transform.rs +++ b/crates/fj-math/src/transform.rs @@ -89,12 +89,12 @@ impl Transform { } /// Inverse transform - pub fn inverse(&self) -> Transform { + pub fn inverse(&self) -> Self { Self(self.0.inverse()) } /// Transpose transform - pub fn transpose(&self) -> Transform { + pub fn transpose(&self) -> Self { Self(nalgebra::Transform::from_matrix_unchecked( self.0.to_homogeneous().transpose(), )) @@ -133,14 +133,14 @@ impl Transform { } /// Extract the rotation component of this transform - pub fn extract_rotation(&self) -> Transform { + pub fn extract_rotation(&self) -> Self { Self(nalgebra::Transform::from_matrix_unchecked( self.0.matrix().fixed_resize::<3, 3>(0.).to_homogeneous(), )) } /// Extract the translation component of this transform - pub fn extract_translation(&self) -> Transform { + pub fn extract_translation(&self) -> Self { *self * self.extract_rotation().inverse() } } diff --git a/crates/fj-math/src/triangle.rs b/crates/fj-math/src/triangle.rs index fb763017f..f3d42da90 100644 --- a/crates/fj-math/src/triangle.rs +++ b/crates/fj-math/src/triangle.rs @@ -58,7 +58,7 @@ impl Triangle { impl Triangle<2> { /// Returns the direction of the line through the points of the triangle. pub fn winding(&self) -> Winding { - let [pa, pb, pc] = self.points.map(|point| point.into()); + let [pa, pb, pc] = self.points.map(Into::into); let orient2d = robust_predicates::orient2d(&pa, &pb, &pc); if orient2d < 0. { @@ -96,7 +96,7 @@ impl Triangle<3> { self.to_parry() .cast_local_ray(&ray, max_toi, solid) - .map(|f| f.into()) + .map(Into::into) } /// Compute the triangle's normal diff --git a/crates/fj-math/src/vector.rs b/crates/fj-math/src/vector.rs index 9fd0b6cb0..b047d939d 100644 --- a/crates/fj-math/src/vector.rs +++ b/crates/fj-math/src/vector.rs @@ -113,19 +113,19 @@ impl Vector { impl Vector<1> { /// Construct a `Vector` that represents the t-axis pub fn unit_t() -> Self { - Vector::from([1.]) + Self::from([1.]) } } impl Vector<2> { /// Construct a `Vector` that represents the u-axis pub fn unit_u() -> Self { - Vector::from([1., 0.]) + Self::from([1., 0.]) } /// Construct a `Vector` that represents the v-axis pub fn unit_v() -> Self { - Vector::from([0., 1.]) + Self::from([0., 1.]) } /// Compute the 2D cross product with another vector @@ -143,17 +143,17 @@ impl Vector<2> { impl Vector<3> { /// Construct a `Vector` that represents the x-axis pub fn unit_x() -> Self { - Vector::from([1., 0., 0.]) + Self::from([1., 0., 0.]) } /// Construct a `Vector` that represents the y-axis pub fn unit_y() -> Self { - Vector::from([0., 1., 0.]) + Self::from([0., 1., 0.]) } /// Construct a `Vector` that represents the z-axis pub fn unit_z() -> Self { - Vector::from([0., 0., 1.]) + Self::from([0., 0., 1.]) } /// Compute the cross product with another vector diff --git a/crates/fj-proc/src/expand.rs b/crates/fj-proc/src/expand.rs index 37644bdbd..d5a887205 100644 --- a/crates/fj-proc/src/expand.rs +++ b/crates/fj-proc/src/expand.rs @@ -7,7 +7,7 @@ use crate::parse::{ }; impl Initializer { - fn register(&self) -> TokenStream { + fn register() -> TokenStream { quote! { const _: () = { fj::register_model!(|host| { @@ -28,20 +28,20 @@ impl Initializer { impl ToTokens for Initializer { fn to_tokens(&self, tokens: &mut TokenStream) { - let Initializer { model } = self; + let Self { model } = self; - tokens.extend(self.register()); + tokens.extend(Self::register()); model.to_tokens(tokens); } } impl Model { - fn definition(&self) -> TokenStream { + fn definition() -> TokenStream { quote! { struct Model; } } fn trait_implementation(&self) -> TokenStream { - let Model { metadata, geometry } = self; + let Self { metadata, geometry } = self; quote! { impl fj::models::Model for Model { @@ -54,14 +54,14 @@ impl Model { impl ToTokens for Model { fn to_tokens(&self, tokens: &mut TokenStream) { - tokens.extend(self.definition()); + tokens.extend(Self::definition()); tokens.extend(self.trait_implementation()); } } impl ToTokens for Metadata { fn to_tokens(&self, tokens: &mut TokenStream) { - let Metadata { name, arguments } = self; + let Self { name, arguments } = self; tokens.extend(quote! { fn metadata(&self) -> fj::models::ModelMetadata { @@ -74,7 +74,7 @@ impl ToTokens for Metadata { impl ToTokens for ArgumentMetadata { fn to_tokens(&self, tokens: &mut TokenStream) { - let ArgumentMetadata { + let Self { name, default_value, } = self; @@ -91,7 +91,7 @@ impl ToTokens for ArgumentMetadata { impl ToTokens for GeometryFunction { fn to_tokens(&self, tokens: &mut TokenStream) { - let GeometryFunction { + let Self { geometry_function, arguments, constraints, @@ -124,7 +124,7 @@ impl ToTokens for GeometryFunction { impl ToTokens for ExtractedArgument { fn to_tokens(&self, tokens: &mut TokenStream) { - let ExtractedArgument { + let Self { ident, ty, default_value, @@ -155,7 +155,7 @@ impl ToTokens for ExtractedArgument { impl ToTokens for Constraint { fn to_tokens(&self, tokens: &mut TokenStream) { - let Constraint { target, expr, kind } = self; + let Self { target, expr, kind } = self; let operator = match kind { ConstraintKind::Max => quote!(<=), diff --git a/crates/fj-proc/src/parse.rs b/crates/fj-proc/src/parse.rs index 529659f6d..911517916 100644 --- a/crates/fj-proc/src/parse.rs +++ b/crates/fj-proc/src/parse.rs @@ -115,9 +115,8 @@ fn contains_result(ty: &Type) -> bool { } fn argument_constraints(arg: &Argument) -> Vec { - let attr = match arg.attr.as_ref() { - Some(a) => a, - None => return Vec::new(), + let Some(attr) = arg.attr.as_ref() else { + return Vec::new() }; let mut constraints = Vec::new(); @@ -167,10 +166,11 @@ impl Argument { impl Parse for Argument { fn parse(input: syn::parse::ParseStream) -> syn::Result { - let mut attr = None; - if input.peek(syn::token::Pound) { - attr = Some(input.parse()?); - } + let attr = if input.peek(syn::token::Pound) { + Some(input.parse()?) + } else { + None + }; let ident: Ident = input.parse()?; let _: syn::token::Colon = input.parse()?; @@ -202,8 +202,7 @@ impl Parse for HelperAttribute { return Err(syn::Error::new_spanned( ident.clone(), format!( - "Unknown attribute \"{}\" found, expected \"param\"", - ident + "Unknown attribute \"{ident}\" found, expected \"param\"" ), )); } diff --git a/crates/fj-viewer/src/graphics/renderer.rs b/crates/fj-viewer/src/graphics/renderer.rs index cea4a85ce..881b1bc2a 100644 --- a/crates/fj-viewer/src/graphics/renderer.rs +++ b/crates/fj-viewer/src/graphics/renderer.rs @@ -204,8 +204,8 @@ impl Renderer { scale_factor: f32, gui: &mut Gui, ) -> Result<(), DrawError> { - let aspect_ratio = self.surface_config.width as f64 - / self.surface_config.height as f64; + let aspect_ratio = f64::from(self.surface_config.width) + / f64::from(self.surface_config.height); let uniforms = Uniforms { transform: Transform::for_vertices(camera, aspect_ratio), transform_normals: Transform::for_normals(camera), diff --git a/crates/fj-viewer/src/gui.rs b/crates/fj-viewer/src/gui.rs index 3e1216776..9ed8fd96e 100644 --- a/crates/fj-viewer/src/gui.rs +++ b/crates/fj-viewer/src/gui.rs @@ -75,7 +75,7 @@ impl Gui { Self { context, render_pass, - options: Default::default(), + options: Options::default(), } } diff --git a/crates/fj-viewer/src/input/handler.rs b/crates/fj-viewer/src/input/handler.rs index 826a11bd1..1c3ad34d4 100644 --- a/crates/fj-viewer/src/input/handler.rs +++ b/crates/fj-viewer/src/input/handler.rs @@ -4,40 +4,26 @@ use crate::camera::{Camera, FocusPoint}; /// Input handling abstraction /// /// Takes user input and applies them to application state. -pub struct InputHandler { - movement: Movement, - rotation: Rotation, - zoom: Zoom, -} +#[derive(Default)] +pub struct InputHandler; impl InputHandler { /// Handle an input event pub fn handle_event( - &mut self, event: InputEvent, focus_point: FocusPoint, camera: &mut Camera, ) { match event { InputEvent::Translation { previous, current } => { - self.movement.apply(previous, current, focus_point, camera) + Movement::apply(previous, current, focus_point, camera); } InputEvent::Rotation { angle_x, angle_y } => { - self.rotation.apply(angle_x, angle_y, focus_point, camera) + Rotation::apply(angle_x, angle_y, focus_point, camera); } InputEvent::Zoom(zoom_delta) => { - self.zoom.apply(zoom_delta, focus_point, camera) + Zoom::apply(zoom_delta, focus_point, camera); } } } } - -impl Default for InputHandler { - fn default() -> Self { - Self { - movement: Movement, - rotation: Rotation, - zoom: Zoom, - } - } -} diff --git a/crates/fj-viewer/src/input/movement.rs b/crates/fj-viewer/src/input/movement.rs index d234453a3..1d1dc02cf 100644 --- a/crates/fj-viewer/src/input/movement.rs +++ b/crates/fj-viewer/src/input/movement.rs @@ -9,7 +9,6 @@ pub struct Movement; impl Movement { pub fn apply( - &mut self, previous: NormalizedScreenPosition, current: NormalizedScreenPosition, focus_point: FocusPoint, diff --git a/crates/fj-viewer/src/input/rotation.rs b/crates/fj-viewer/src/input/rotation.rs index 1076036da..35ee9591f 100644 --- a/crates/fj-viewer/src/input/rotation.rs +++ b/crates/fj-viewer/src/input/rotation.rs @@ -6,7 +6,6 @@ pub struct Rotation; impl Rotation { pub fn apply( - &self, angle_x: f64, angle_y: f64, focus_point: FocusPoint, diff --git a/crates/fj-viewer/src/input/zoom.rs b/crates/fj-viewer/src/input/zoom.rs index 9c6e495b7..3cccf1b41 100644 --- a/crates/fj-viewer/src/input/zoom.rs +++ b/crates/fj-viewer/src/input/zoom.rs @@ -6,7 +6,6 @@ pub struct Zoom; impl Zoom { pub fn apply( - &mut self, zoom_delta: f64, focus_point: FocusPoint, camera: &mut Camera, diff --git a/crates/fj-viewer/src/viewer.rs b/crates/fj-viewer/src/viewer.rs index db03c42f4..bc6540e1c 100644 --- a/crates/fj-viewer/src/viewer.rs +++ b/crates/fj-viewer/src/viewer.rs @@ -57,20 +57,20 @@ impl Viewer { /// Toggle the "draw model" setting pub fn toggle_draw_model(&mut self) { - self.draw_config.draw_model = !self.draw_config.draw_model + self.draw_config.draw_model = !self.draw_config.draw_model; } /// Toggle the "draw mesh" setting pub fn toggle_draw_mesh(&mut self) { if self.renderer.is_line_drawing_available() { - self.draw_config.draw_mesh = !self.draw_config.draw_mesh + self.draw_config.draw_mesh = !self.draw_config.draw_mesh; } } /// Toggle the "draw debug" setting pub fn toggle_draw_debug(&mut self) { if self.renderer.is_line_drawing_available() { - self.draw_config.draw_debug = !self.draw_config.draw_debug + self.draw_config.draw_debug = !self.draw_config.draw_debug; } } @@ -81,24 +81,20 @@ impl Viewer { let aabb = shape.aabb; if self.shape.replace(shape).is_none() { - self.camera.init_planes(&aabb) + self.camera.init_planes(&aabb); } } /// Handle an input event pub fn handle_input_event(&mut self, event: InputEvent) { if let Some(focus_point) = self.focus_point { - self.input_handler.handle_event( - event, - focus_point, - &mut self.camera, - ); + InputHandler::handle_event(event, focus_point, &mut self.camera); } } /// Handle the screen being resized pub fn handle_screen_resize(&mut self, screen_size: ScreenSize) { - self.renderer.handle_resize(screen_size) + self.renderer.handle_resize(screen_size); } /// Compute and store a focus point, unless one is already stored diff --git a/crates/fj-window/src/event_loop_handler.rs b/crates/fj-window/src/event_loop_handler.rs index c737b3cf6..1e311d1d8 100644 --- a/crates/fj-window/src/event_loop_handler.rs +++ b/crates/fj-window/src/event_loop_handler.rs @@ -45,15 +45,15 @@ impl EventLoopHandler { let event = events .try_recv() .map_err(|err| { - if err.is_disconnected() { - panic!("Expected channel to never disconnect"); - } + assert!( + !err.is_disconnected(), + "Expected channel to never disconnect" + ); }) .ok(); - let event = match event { - Some(status_update) => status_update, - None => break, + let Some(event) = event else { + break }; match event { @@ -249,7 +249,7 @@ fn input_event( } => { let delta = match delta { MouseScrollDelta::LineDelta(_, y) => { - (*y as f64) * ZOOM_FACTOR_LINE + f64::from(*y) * ZOOM_FACTOR_LINE } MouseScrollDelta::PixelDelta(PhysicalPosition { y, .. diff --git a/crates/fj-window/src/run.rs b/crates/fj-window/src/run.rs index f58e26565..8b9999deb 100644 --- a/crates/fj-window/src/run.rs +++ b/crates/fj-window/src/run.rs @@ -65,13 +65,13 @@ fn handle_error( let mut msg = String::new(); - writeln!(msg, "Shape processing error: {}", err)?; + writeln!(msg, "Shape processing error: {err}")?; let mut current_err = &err as &dyn error::Error; while let Some(err) = current_err.source() { writeln!(msg)?; writeln!(msg, "Caused by:")?; - writeln!(msg, " {}", err)?; + writeln!(msg, " {err}")?; current_err = err; } diff --git a/crates/fj/src/abi/ffi_safe.rs b/crates/fj/src/abi/ffi_safe.rs index b0965f8f0..0aa23a257 100644 --- a/crates/fj/src/abi/ffi_safe.rs +++ b/crates/fj/src/abi/ffi_safe.rs @@ -55,7 +55,7 @@ impl From> for Vec { // the items are gone, time to free the original vec drop(items); - Vec { ptr, len } + Self { ptr, len } } } } @@ -74,7 +74,7 @@ impl Clone for Vec { impl From> for Box<[T]> { fn from(v: Vec) -> Self { - Box::from(&*v) + Self::from(&*v) } } @@ -98,7 +98,7 @@ impl Deref for Vec { // Safety: We control "ptr" and "len", so we know they are always // initialized and within bounds. unsafe { - let Vec { ptr, len } = *self; + let Self { ptr, len } = *self; std::slice::from_raw_parts(ptr.as_ptr(), len) } } @@ -106,7 +106,7 @@ impl Deref for Vec { impl Drop for Vec { fn drop(&mut self) { - let Vec { ptr, len } = *self; + let Self { ptr, len } = *self; let ptr = ptr.as_ptr(); for i in 0..self.len { @@ -169,7 +169,7 @@ pub struct String(Vec); impl From for String { fn from(s: std::string::String) -> Self { - String(s.into_bytes().into()) + Self(s.into_bytes().into()) } } @@ -181,7 +181,7 @@ impl From for std::string::String { impl From for Box { fn from(s: String) -> Self { - Box::from(&*s) + Self::from(&*s) } } impl PartialEq for String { @@ -223,8 +223,8 @@ pub enum Result { impl Result { pub fn unwrap(self) -> T { match self { - Result::Ok(value) => value, - Result::Err(e) => panic!("Unwrapped an Err({e:?})"), + Self::Ok(value) => value, + Self::Err(e) => panic!("Unwrapped an Err({e:?})"), } } } @@ -232,8 +232,8 @@ impl Result { impl From> for Result { fn from(result: std::result::Result) -> Self { match result { - Ok(ok) => Result::Ok(ok), - Err(err) => Result::Err(err), + Ok(ok) => Self::Ok(ok), + Err(err) => Self::Err(err), } } } @@ -241,8 +241,8 @@ impl From> for Result { impl From> for std::result::Result { fn from(result: Result) -> Self { match result { - Result::Ok(ok) => std::result::Result::Ok(ok), - Result::Err(err) => std::result::Result::Err(err), + Result::Ok(ok) => Self::Ok(ok), + Result::Err(err) => Self::Err(err), } } } @@ -263,7 +263,7 @@ impl Slice { pub unsafe fn from_slice(items: &[T]) -> Self { let ptr = items.as_ptr(); let len = items.len(); - Slice { + Self { // Safety: It's okay to cast away the const because you can't mutate // a slice. ptr: NonNull::new(ptr as *mut T).unwrap(), @@ -272,7 +272,7 @@ impl Slice { } pub unsafe fn into_slice<'a>(self) -> &'a [T] { - let Slice { ptr, len } = self; + let Self { ptr, len } = self; std::slice::from_raw_parts(ptr.as_ptr(), len) } } @@ -300,7 +300,7 @@ impl Deref for Slice { // this should be safe as long as people can never get a Slice that // outlives the data it points to. unsafe { - let Slice { ptr, len, .. } = *self; + let Self { ptr, len, .. } = *self; std::slice::from_raw_parts(ptr.as_ptr(), len) } } @@ -316,8 +316,8 @@ impl StringSlice { /// /// It is the caller's responsibility to make sure this [`Slice`] doesn't /// outlive the slice that was passed in. - pub unsafe fn from_str(s: &str) -> StringSlice { - StringSlice(Slice::from_slice(s.as_bytes())) + pub unsafe fn from_str(s: &str) -> Self { + Self(Slice::from_slice(s.as_bytes())) } pub unsafe fn into_str<'a>(self) -> &'a str { @@ -356,7 +356,7 @@ impl From for BoxedError { // where `Source` is a private wrapper around String that implements // std::error::Error, however then people will see what *looks* like a // particular error type, but they won't be able to downcast to it. - BoxedError { + Self { msg: err.to_string().into(), } } @@ -372,8 +372,8 @@ pub enum Option { impl Option { pub fn map(self, func: impl FnOnce(T) -> T2) -> Option { match self { - Option::Some(value) => Option::Some(func(value)), - Option::None => Option::None, + Self::Some(value) => Option::Some(func(value)), + Self::None => Option::None, } } } @@ -384,8 +384,8 @@ where { fn from(opt: std::option::Option) -> Self { match opt { - Some(value) => Option::Some(value.into()), - None => Option::None, + Some(value) => Self::Some(value.into()), + None => Self::None, } } } diff --git a/crates/fj/src/abi/host.rs b/crates/fj/src/abi/host.rs index 2b61cee95..31d61edf2 100644 --- a/crates/fj/src/abi/host.rs +++ b/crates/fj/src/abi/host.rs @@ -19,7 +19,7 @@ impl<'a, H: crate::models::Host + Sized> From<&'a mut H> for Host<'a> { let host = unsafe { &mut *(user_data as *mut H) }; if let Err(e) = std::panic::catch_unwind(AssertUnwindSafe(|| { - host.register_boxed_model(Box::new(model)) + host.register_boxed_model(Box::new(model)); })) { crate::abi::on_panic(e); } diff --git a/crates/fj/src/abi/metadata.rs b/crates/fj/src/abi/metadata.rs index b21c0bd3a..7d56d8698 100644 --- a/crates/fj/src/abi/metadata.rs +++ b/crates/fj/src/abi/metadata.rs @@ -16,10 +16,10 @@ impl From for crate::models::ModelMetadata { arguments, } = m; - crate::models::ModelMetadata { + Self { name: name.into(), description: description.map(Into::into).into(), - arguments: arguments.iter().cloned().map(|a| a.into()).collect(), + arguments: arguments.iter().cloned().map(Into::into).collect(), } } } @@ -32,7 +32,7 @@ impl From for ModelMetadata { arguments, } = m; - ModelMetadata { + Self { name: name.into(), description: description.into(), arguments: arguments.into_iter().map(Into::into).collect(), @@ -64,7 +64,7 @@ impl From for crate::models::Metadata { license, } = m; - crate::models::Metadata { + Self { name: name.into(), version: version.into(), short_description: short_description.map(Into::into).into(), @@ -88,7 +88,7 @@ impl From for Metadata { license, } = m; - Metadata { + Self { name: name.into(), version: version.into(), short_description: short_description.into(), @@ -116,7 +116,7 @@ impl From for ArgumentMetadata { default_value, } = meta; - ArgumentMetadata { + Self { name: name.into(), description: description.into(), default_value: default_value.into(), @@ -132,7 +132,7 @@ impl From for crate::models::ArgumentMetadata { default_value, } = meta; - crate::models::ArgumentMetadata { + Self { name: name.into(), description: description.map(Into::into).into(), default_value: default_value.map(Into::into).into(), diff --git a/crates/fj/src/abi/model.rs b/crates/fj/src/abi/model.rs index eb7def772..d4c14ee1e 100644 --- a/crates/fj/src/abi/model.rs +++ b/crates/fj/src/abi/model.rs @@ -20,7 +20,7 @@ impl crate::models::Model for Model { ) -> Result { let ctx = Context::from(&ctx); - let Model { ptr, shape, .. } = *self; + let Self { ptr, shape, .. } = *self; let result = unsafe { shape(ptr, ctx) }; @@ -31,7 +31,7 @@ impl crate::models::Model for Model { } fn metadata(&self) -> crate::models::ModelMetadata { - let Model { ptr, metadata, .. } = *self; + let Self { ptr, metadata, .. } = *self; unsafe { metadata(ptr).into() } } @@ -76,7 +76,7 @@ impl From> for Model { }; } - Model { + Self { ptr: Box::into_raw(Box::new(m)).cast(), metadata, shape, @@ -87,7 +87,7 @@ impl From> for Model { impl Drop for Model { fn drop(&mut self) { - let Model { ptr, free, .. } = *self; + let Self { ptr, free, .. } = *self; unsafe { free(ptr); diff --git a/crates/fj/src/angle.rs b/crates/fj/src/angle.rs index 437a305bb..b4f1cfb12 100644 --- a/crates/fj/src/angle.rs +++ b/crates/fj/src/angle.rs @@ -64,7 +64,7 @@ impl Angle { } impl std::ops::Add for Angle { - type Output = Angle; + type Output = Self; fn add(self, rhs: Self) -> Self::Output { Self::from_rad(self.rad + rhs.rad) } @@ -73,12 +73,12 @@ impl std::ops::Add for Angle { impl std::ops::AddAssign for Angle { fn add_assign(&mut self, rhs: Self) { self.rad += rhs.rad; - self.wrap_assign() + self.wrap_assign(); } } impl std::ops::Sub for Angle { - type Output = Angle; + type Output = Self; fn sub(self, rhs: Self) -> Self::Output { Self::from_rad(self.rad - rhs.rad) } @@ -87,12 +87,12 @@ impl std::ops::Sub for Angle { impl std::ops::SubAssign for Angle { fn sub_assign(&mut self, rhs: Self) { self.rad -= rhs.rad; - self.wrap_assign() + self.wrap_assign(); } } impl std::ops::Mul for Angle { - type Output = Angle; + type Output = Self; fn mul(self, rhs: f64) -> Self::Output { Self::from_rad(self.rad * rhs) } @@ -108,12 +108,12 @@ impl std::ops::Mul for f64 { impl std::ops::MulAssign for Angle { fn mul_assign(&mut self, rhs: f64) { self.rad *= rhs; - self.wrap_assign() + self.wrap_assign(); } } impl std::ops::Div for Angle { - type Output = Angle; + type Output = Self; fn div(self, rhs: f64) -> Self::Output { Self::from_rad(self.rad / rhs) } @@ -122,13 +122,13 @@ impl std::ops::Div for Angle { impl std::ops::DivAssign for Angle { fn div_assign(&mut self, rhs: f64) { self.rad /= rhs; - self.wrap_assign() + self.wrap_assign(); } } impl std::ops::Div for Angle { type Output = f64; - fn div(self, rhs: Angle) -> Self::Output { + fn div(self, rhs: Self) -> Self::Output { self.rad / rhs.rad } } diff --git a/crates/fj/src/models/metadata.rs b/crates/fj/src/models/metadata.rs index 398ab3be4..0ce58c0e5 100644 --- a/crates/fj/src/models/metadata.rs +++ b/crates/fj/src/models/metadata.rs @@ -41,7 +41,7 @@ impl Metadata { let version = version.into(); assert!(!version.is_empty()); - Metadata { + Self { name, version, short_description: None, @@ -62,7 +62,7 @@ impl Metadata { return self; } - Metadata { + Self { short_description: Some(short_description), ..self } @@ -75,7 +75,7 @@ impl Metadata { return self; } - Metadata { + Self { description: Some(description), ..self } @@ -88,7 +88,7 @@ impl Metadata { return self; } - Metadata { + Self { homepage: Some(homepage), ..self } @@ -101,7 +101,7 @@ impl Metadata { return self; } - Metadata { + Self { repository: Some(repository), ..self } @@ -114,7 +114,7 @@ impl Metadata { return self; } - Metadata { + Self { license: Some(license), ..self } @@ -144,7 +144,7 @@ impl ModelMetadata { let name = name.into(); assert!(!name.is_empty()); - ModelMetadata { + Self { name, description: None, arguments: Vec::new(), @@ -158,7 +158,7 @@ impl ModelMetadata { return self; } - ModelMetadata { + Self { description: Some(description), ..self } @@ -197,7 +197,7 @@ impl ArgumentMetadata { pub fn new(name: impl Into) -> Self { let name = name.into(); assert!(!name.is_empty()); - ArgumentMetadata { + Self { name, description: None, default_value: None, @@ -227,6 +227,6 @@ impl ArgumentMetadata { impl From<&str> for ArgumentMetadata { fn from(name: &str) -> Self { - ArgumentMetadata::new(name) + Self::new(name) } } diff --git a/crates/fj/src/shape_2d.rs b/crates/fj/src/shape_2d.rs index 87a933870..b1b3b5649 100644 --- a/crates/fj/src/shape_2d.rs +++ b/crates/fj/src/shape_2d.rs @@ -16,8 +16,8 @@ impl Shape2d { /// Get the rendering color of the larger object in RGBA pub fn color(&self) -> [u8; 4] { match &self { - Shape2d::Sketch(s) => s.color(), - Shape2d::Difference(d) => d.color(), + Self::Sketch(s) => s.color(), + Self::Difference(d) => d.color(), } } } @@ -142,7 +142,7 @@ impl From for Shape { impl From for Shape2d { fn from(shape: Sketch) -> Self { - Shape2d::Sketch(shape) + Self::Sketch(shape) } } diff --git a/tools/autolib/src/lib.rs b/tools/autolib/src/lib.rs index b236addac..8a307281e 100644 --- a/tools/autolib/src/lib.rs +++ b/tools/autolib/src/lib.rs @@ -9,7 +9,7 @@ pub fn find_version_in_str(s: &str) -> anyhow::Result> { version.as_str(), ); }) - .filter_map(|m| { + .find_map(|m| { let version = semver::Version::parse(m.as_str()).ok(); if version.is_some() { @@ -19,8 +19,7 @@ pub fn find_version_in_str(s: &str) -> anyhow::Result> { } version - }) - .next(); + }); Ok(version) } diff --git a/tools/automator/src/pull_requests.rs b/tools/automator/src/pull_requests.rs index fa8b08a1a..1932dae17 100644 --- a/tools/automator/src/pull_requests.rs +++ b/tools/automator/src/pull_requests.rs @@ -23,7 +23,7 @@ impl PullRequestsSinceLastRelease { let (version_of_last_release, time_of_last_release) = 'outer: loop { const MAX_RESULTS_PER_PAGE: u8 = 100; - println!("Fetching page {}...", page); + println!("Fetching page {page}..."); let pull_request_page = octocrab .pulls("hannobraun", "Fornjot") .list() diff --git a/tools/automator/src/sponsors.rs b/tools/automator/src/sponsors.rs index 2376efbac..9013cacdd 100644 --- a/tools/automator/src/sponsors.rs +++ b/tools/automator/src/sponsors.rs @@ -9,7 +9,7 @@ pub struct Sponsors { } impl Sponsors { - pub async fn query(octocrab: &Octocrab) -> anyhow::Result { + pub async fn query(octocrab: &Octocrab) -> anyhow::Result { let response: QueryResult = octocrab .graphql( "query { @@ -74,7 +74,7 @@ impl Sponsors { sponsors.sort(); - Ok(Sponsors { inner: sponsors }) + Ok(Self { inner: sponsors }) } pub fn as_markdown( diff --git a/tools/release-operator/src/registry.rs b/tools/release-operator/src/registry.rs index ddacb1b2e..0d0b03027 100644 --- a/tools/release-operator/src/registry.rs +++ b/tools/release-operator/src/registry.rs @@ -257,7 +257,7 @@ impl FromStr for Crate { type Err = String; fn from_str(s: &str) -> Result { - Ok(Crate { + Ok(Self { path: PathBuf::from(s), }) } diff --git a/tools/release-operator/src/release.rs b/tools/release-operator/src/release.rs index 070281f1d..7d5b99f0a 100644 --- a/tools/release-operator/src/release.rs +++ b/tools/release-operator/src/release.rs @@ -16,8 +16,8 @@ pub enum Outputs { impl Display for Outputs { fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { match &self { - Outputs::ReleaseDetected => write!(f, "release-detected"), - Outputs::TagName => write!(f, "tag-name"), + Self::ReleaseDetected => write!(f, "release-detected"), + Self::TagName => write!(f, "tag-name"), } } } @@ -38,7 +38,7 @@ impl Release { "Could not find a pull request with hash {sha} and label \ {label}", ); - return self.miss(); + return Self::miss(); } let commit: String = cmd_lib::run_fun!(git log -n 1 "${sha}")?; @@ -47,18 +47,18 @@ impl Release { let version = find_version_in_str(&commit)?; match version { - Some(v) => self.hit(&v.to_string()), + Some(v) => Self::hit(&v.to_string()), None => { log::info!( "Commit message is missing version number:\n\ {commit}", ); - self.miss() + Self::miss() } } } - fn hit(&self, tag: &str) -> anyhow::Result<()> { + fn hit(tag: &str) -> anyhow::Result<()> { let tag = format!("v{tag}"); log::info!("detected release of {tag}"); @@ -70,7 +70,7 @@ impl Release { Ok(()) } - fn miss(&self) -> anyhow::Result<()> { + fn miss() -> anyhow::Result<()> { log::info!("no release detected"); Actions::set_output([(Outputs::ReleaseDetected, "false")])?; Ok(())