tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 1061HTML 997Markdown 12TOML 83120 Sutichaykuna

removed the ToNumber trait, use std::convert::From instead

a74a6698cecd9ec1a379e265e8a5b2f808113913 · ruwaq Adam Nemecek · (6 wata ñawpaq) · tayta 0011d0c9f · kay commitpi sach'ata qhaway

Semántico sayk'uy · 7

src/algo.rs

src/number.rs

2 qillqakuna · +23 −27

diff --git a/src/algo.rs b/src/algo.rs
index 7cb5ae4fd..567dcdbcb 100644
--- a/src/algo.rs
+++ b/src/algo.rs
@@ -73,13 +73,13 @@ impl Forest {
                         .width
                         .maybe_max(style.min_size.width.resolve(size.width))
                         .maybe_min(style.max_size.width.resolve(size.width))
-                        .to_number(),
+                        .into(),
                     height: first_pass
                         .size
                         .height
                         .maybe_max(style.min_size.height.resolve(size.height))
                         .maybe_min(style.max_size.height.resolve(size.height))
-                        .to_number(),
+                        .into(),
                 },
                 size,
                 true,
@@ -358,7 +358,7 @@ impl Forest {
                 .main(dir)
                 .maybe_max(child.min_size.main(dir))
                 .maybe_min(child.size.main(dir))
-                .to_number();
+                .into();
 
             child
                 .hypothetical_inner_size
@@ -608,7 +608,7 @@ impl Forest {
                         .width
                         .maybe_min(child.size.width)
                         .maybe_max(child.min_size.width)
-                        .to_number()
+                        .into()
                     } else {
                         child.min_size.main(dir)
                     };
@@ -677,12 +677,12 @@ impl Forest {
                     self.compute_internal(
                         child.node,
                         Size {
-                            width: if is_row { child.target_size.width.to_number() } else { child_cross },
-                            height: if is_row { child_cross } else { child.target_size.height.to_number() },
+                            width: if is_row { child.target_size.width.into() } else { child_cross },
+                            height: if is_row { child_cross } else { child.target_size.height.into() },
                         },
                         Size {
-                            width: if is_row { container_size.main(dir).to_number() } else { available_space.width },
-                            height: if is_row { available_space.height } else { container_size.main(dir).to_number() },
+                            width: if is_row { container_size.main(dir).into() } else { available_space.width },
+                            height: if is_row { available_space.height } else { container_size.main(dir).into() },
                         },
                         false,
                     )
@@ -717,19 +717,19 @@ impl Forest {
                         child.node,
                         Size {
                             width: if is_row {
-                                child.target_size.width.to_number()
+                                child.target_size.width.into()
                             } else {
-                                child.hypothetical_inner_size.width.to_number()
+                                child.hypothetical_inner_size.width.into()
                             },
                             height: if is_row {
-                                child.hypothetical_inner_size.height.to_number()
+                                child.hypothetical_inner_size.height.into()
                             } else {
-                                child.target_size.height.to_number()
+                                child.target_size.height.into()
                             },
                         },
                         Size {
-                            width: if is_row { container_size.width.to_number() } else { node_size.width },
-                            height: if is_row { node_size.height } else { container_size.height.to_number() },
+                            width: if is_row { container_size.width.into() } else { node_size.width },
+                            height: if is_row { node_size.height } else { container_size.height.into() },
                         },
                         true,
                     );
@@ -1127,8 +1127,8 @@ impl Forest {
                 let layout_item = |child: &mut FlexItem| {
                     let result = self.compute_internal(
                         child.node,
-                        child.target_size.map(|s| s.to_number()),
-                        container_size.map(|s| s.to_number()),
+                        child.target_size.map(|s| s.into()),
+                        container_size.map(|s| s.into()),
                         true,
                     );
 
@@ -1182,8 +1182,8 @@ impl Forest {
                 .collect::<sys::Vec<_>>();
 
             for (order, child) in candidates {
-                let container_width = container_size.width.to_number();
-                let container_height = container_size.height.to_number();
+                let container_width = container_size.width.into();
+                let container_height = container_size.height.into();
 
                 let child_style = self.nodes[child].style;
 
diff --git a/src/number.rs b/src/number.rs
index a744b09a8..f5dc0aed1 100644
--- a/src/number.rs
+++ b/src/number.rs
@@ -9,10 +9,6 @@ pub enum Number {
     Undefined,
 }
 
-pub trait ToNumber {
-    fn to_number(self) -> Number;
-}
-
 pub trait OrElse<T> {
     fn or_else(self, other: T) -> T;
 }
@@ -81,14 +77,14 @@ impl MinMax<Self, Self> for Number {
 }
 
 impl MinMax<f32, Number> for Number {
-    fn maybe_min(self, rhs: f32) -> Number {
+    fn maybe_min(self, rhs: f32) -> Self {
         match self {
             Number::Defined(val) => Number::Defined(val.min(rhs)),
             Number::Undefined => Number::Undefined,
         }
     }
 
-    fn maybe_max(self, rhs: f32) -> Number {
+    fn maybe_max(self, rhs: f32) -> Self {
         match self {
             Number::Defined(val) => Number::Defined(val.max(rhs)),
             Number::Undefined => Number::Undefined,
@@ -112,9 +108,9 @@ impl MinMax<Number, f32> for f32 {
     }
 }
 
-impl ToNumber for f32 {
-    fn to_number(self) -> Number {
-        Number::Defined(self)
+impl From<f32> for Number {
+    fn from(v: f32) -> Self {
+        Self::Defined(v)
     }
 }