summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJovansonlee Cesar <ivanceras@gmail.com>2022-09-23 17:43:56 +0800
committerJovansonlee Cesar <ivanceras@gmail.com>2022-09-23 17:43:56 +0800
commit1a66cd5d7bdbf83371bcfd2f7ed61b18bdc88f02 (patch)
tree4578a47c3f546b5ae72ae86c01c8b1c3e8d4a315
parentd23bbf96c8f3eddfe39e279b4a31dabc4e03c120 (diff)
fix: more clippy warnings
-rw-r--r--packages/svgbob/src/buffer/fragment_buffer/fragment.rs5
-rw-r--r--packages/svgbob/src/buffer/fragment_buffer/fragment/rect.rs58
-rw-r--r--packages/svgbob/src/buffer/fragment_buffer/fragment/text.rs34
3 files changed, 47 insertions, 50 deletions
diff --git a/packages/svgbob/src/buffer/fragment_buffer/fragment.rs b/packages/svgbob/src/buffer/fragment_buffer/fragment.rs
index 2899572..c1c2393 100644
--- a/packages/svgbob/src/buffer/fragment_buffer/fragment.rs
+++ b/packages/svgbob/src/buffer/fragment_buffer/fragment.rs
@@ -72,10 +72,9 @@ pub trait Bounds {
impl Fragment {
/// get the character that matches the shape present on this cell
- pub fn match_unicode(fragments: &Vec<Self>) -> Option<char> {
- let mut sorted_shapes = fragments.clone();
+ pub fn match_unicode(fragments: &[Fragment]) -> Option<char> {
+ let mut sorted_shapes: Vec<Fragment> = fragments.to_vec();
sorted_shapes.sort();
- //assert!(sorted_shapes.is_sorted());
FRAGMENTS_UNICODE.get(&sorted_shapes).copied()
}
diff --git a/packages/svgbob/src/buffer/fragment_buffer/fragment/rect.rs b/packages/svgbob/src/buffer/fragment_buffer/fragment/rect.rs
index 7ae8f21..c325c2e 100644
--- a/packages/svgbob/src/buffer/fragment_buffer/fragment/rect.rs
+++ b/packages/svgbob/src/buffer/fragment_buffer/fragment/rect.rs
@@ -22,7 +22,7 @@ pub struct Rect {
impl Rect {
/// creates a new rect and reorder the points swapping the end points if necessary
/// such that the start is the most top-left and end point is the most bottom-right
- pub(in crate) fn new(
+ pub(crate) fn new(
start: Point,
end: Point,
is_filled: bool,
@@ -39,7 +39,7 @@ impl Rect {
rect
}
- pub(in crate) fn rounded_new(
+ pub(crate) fn rounded_new(
start: Point,
end: Point,
is_filled: bool,
@@ -59,7 +59,7 @@ impl Rect {
/// reorder the end points swap end points such that
/// start < end
- pub(in crate) fn sort_reorder_end_points(&mut self) {
+ pub(crate) fn sort_reorder_end_points(&mut self) {
if self.start > self.end {
std::mem::swap(&mut self.start, &mut self.end);
}
@@ -67,7 +67,7 @@ impl Rect {
/// recompute the rect with start and end point offset by the cell
/// location
- pub(in crate) fn absolute_position(&self, cell: Cell) -> Self {
+ pub(crate) fn absolute_position(&self, cell: Cell) -> Self {
Rect {
start: cell.absolute_position(self.start),
end: cell.absolute_position(self.end),
@@ -75,7 +75,7 @@ impl Rect {
}
}
- pub(in crate) fn scale(&self, scale: f32) -> Self {
+ pub(crate) fn scale(&self, scale: f32) -> Self {
Rect {
start: self.start.scale(scale),
end: self.end.scale(scale),
@@ -118,48 +118,48 @@ impl fmt::Display for Rect {
}
}
-impl Into<Polyline> for Rect {
- fn into(self) -> Polyline {
+impl From<Rect> for Polyline {
+ fn from(rect: Rect) -> Polyline {
Polyline::new(
vec![
- *self.start,
- *Point::new(self.end.x, self.start.y),
- *self.end,
- *Point::new(self.start.x, self.end.y),
- *self.start,
+ *rect.start,
+ *Point::new(rect.end.x, rect.start.y),
+ *rect.end,
+ *Point::new(rect.start.x, rect.end.y),
+ *rect.start,
],
None,
)
}
}
-impl Into<ConvexPolygon> for Rect {
- fn into(self) -> ConvexPolygon {
+impl From<Rect> for ConvexPolygon {
+ fn from(rect: Rect) -> ConvexPolygon {
ConvexPolygon::from_convex_polyline(vec![
- *self.start,
- *Point::new(self.end.x, self.start.y),
- *self.end,
- *Point::new(self.start.x, self.end.y),
+ *rect.start,
+ *Point::new(rect.end.x, rect.start.y),
+ *rect.end,
+ *Point::new(rect.start.x, rect.end.y),
])
.expect("must create a convex polygon")
}
}
-impl<MSG> Into<Node<MSG>> for Rect {
- fn into(self) -> Node<MSG> {
+impl<MSG> From<Rect> for Node<MSG> {
+ fn from(r: Rect) -> Node<MSG> {
rect(
[
- x(self.start.x),
- y(self.start.y),
- width(self.width()),
- height(self.height()),
+ x(r.start.x),
+ y(r.start.y),
+ width(r.width()),
+ height(r.height()),
classes_flag([
- ("broken", self.is_broken),
- ("solid", !self.is_broken),
- ("filled", self.is_filled),
- ("nofill", !self.is_filled),
+ ("broken", r.is_broken),
+ ("solid", !r.is_broken),
+ ("filled", r.is_filled),
+ ("nofill", !r.is_filled),
]),
- if let Some(radius) = self.radius {
+ if let Some(radius) = r.radius {
rx(radius)
} else {
rx(0)
diff --git a/packages/svgbob/src/buffer/fragment_buffer/fragment/text.rs b/packages/svgbob/src/buffer/fragment_buffer/fragment/text.rs
index 924d1bf..c750e07 100644
--- a/packages/svgbob/src/buffer/fragment_buffer/fragment/text.rs
+++ b/packages/svgbob/src/buffer/fragment_buffer/fragment/text.rs
@@ -91,31 +91,29 @@ impl Bounds for CellText {
}
}
-impl Into<Text> for CellText {
- fn into(self) -> Text {
- Text::new(self.start.q(), self.content)
+impl From<CellText> for Text {
+ fn from(ct: CellText) -> Text {
+ Text::new(ct.start.q(), ct.content)
}
}
-impl<MSG> Into<Node<MSG>> for CellText {
- fn into(self) -> Node<MSG> {
- let text: Text = self.into();
+impl<MSG> From<CellText> for Node<MSG> {
+ fn from(ct: CellText) -> Node<MSG> {
+ let text: Text = ct.into();
text.into()
}
}
-impl Into<FragmentSpan> for CellText {
- fn into(self) -> FragmentSpan {
- let cells: Vec<(Cell, char)> = self
+impl From<CellText> for FragmentSpan {
+ fn from(ct: CellText) -> FragmentSpan {
+ let cells: Vec<(Cell, char)> = ct
.content
.chars()
.into_iter()
.enumerate()
- .map(|(i, ch)| {
- (Cell::new(self.start.x + i as i32, self.start.y), ch)
- })
+ .map(|(i, ch)| (Cell::new(ct.start.x + i as i32, ct.start.y), ch))
.collect();
- FragmentSpan::new(Span::from(cells), self.into())
+ FragmentSpan::new(Span::from(cells), ct.into())
}
}
@@ -179,14 +177,14 @@ impl fmt::Display for Text {
}
}
-impl<MSG> Into<Node<MSG>> for Text {
- fn into(self) -> Node<MSG> {
+impl<MSG> From<Text> for Node<MSG> {
+ fn from(t: Text) -> Node<MSG> {
svg::tags::text(
- [x(self.start.x), y(self.start.y)],
+ [x(t.start.x), y(t.start.y)],
#[cfg(not(feature = "with-dom"))]
- [text(escape_html_text(&self.text))],
+ [text(escape_html_text(&t.text))],
#[cfg(feature = "with-dom")]
- [text(&self.text)],
+ [text(&t.text)],
)
}
}