diff options
| author | Laurenz <laurmaedje@gmail.com> | 2020-08-30 22:18:55 +0200 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2020-08-30 22:18:55 +0200 |
| commit | 181f756a9e8f7b664101058fe91e36b3858c2d02 (patch) | |
| tree | 542e7c694e91d8cc91fa97a328e9bda0567db679 /src/compute | |
| parent | 0d44cf532136f3ba8e34d6f967f9e844cfb9c3f0 (diff) | |
Format everything with rustfmt! 💚
Diffstat (limited to 'src/compute')
| -rw-r--r-- | src/compute/scope.rs | 4 | ||||
| -rw-r--r-- | src/compute/table.rs | 11 | ||||
| -rw-r--r-- | src/compute/value.rs | 46 |
3 files changed, 33 insertions, 28 deletions
diff --git a/src/compute/scope.rs b/src/compute/scope.rs index 3ab56561..8e6576d1 100644 --- a/src/compute/scope.rs +++ b/src/compute/scope.rs @@ -14,9 +14,7 @@ impl Scope { // Create a new empty scope with a fallback function that is invoked when no // match is found. pub fn new() -> Self { - Self { - functions: HashMap::new(), - } + Self { functions: HashMap::new() } } /// Associate the given name with the function. diff --git a/src/compute/table.rs b/src/compute/table.rs index bb71d4f2..b969c8dc 100644 --- a/src/compute/table.rs +++ b/src/compute/table.rs @@ -117,7 +117,8 @@ impl<V> Table<V> { /// Iterator over all borrowed keys and values. pub fn iter(&self) -> impl Iterator<Item = (BorrowedKey, &V)> { - self.nums().map(|(&k, v)| (BorrowedKey::Num(k), v)) + self.nums() + .map(|(&k, v)| (BorrowedKey::Num(k), v)) .chain(self.strs().map(|(k, v)| (BorrowedKey::Str(k), v))) } @@ -138,13 +139,17 @@ impl<V> Table<V> { /// Move into an owned iterator over owned keys and values. pub fn into_iter(self) -> impl Iterator<Item = (OwnedKey, V)> { - self.nums.into_iter().map(|(k, v)| (OwnedKey::Num(k), v)) + self.nums + .into_iter() + .map(|(k, v)| (OwnedKey::Num(k), v)) .chain(self.strs.into_iter().map(|(k, v)| (OwnedKey::Str(k), v))) } /// Move into an owned iterator over all values in the table. pub fn into_values(self) -> impl Iterator<Item = V> { - self.nums.into_iter().map(|(_, v)| v) + self.nums + .into_iter() + .map(|(_, v)| v) .chain(self.strs.into_iter().map(|(_, v)| v)) } diff --git a/src/compute/value.rs b/src/compute/value.rs index bac6396d..9f1174ec 100644 --- a/src/compute/value.rs +++ b/src/compute/value.rs @@ -6,15 +6,15 @@ use std::rc::Rc; use fontdock::{FontStyle, FontWeight, FontWidth}; +use super::table::{SpannedEntry, Table}; use crate::color::RgbaColor; use crate::layout::{Command, Commands, Dir, LayoutContext, SpecAlign}; use crate::length::{Length, ScaleLength}; use crate::paper::Paper; use crate::syntax::span::{Span, Spanned}; -use crate::syntax::tree::{SyntaxTree, SyntaxNode}; +use crate::syntax::tree::{SyntaxNode, SyntaxTree}; use crate::syntax::Ident; use crate::{DynFuture, Feedback, Pass}; -use super::table::{SpannedEntry, Table}; /// A computational value. #[derive(Clone)] @@ -78,9 +78,10 @@ impl Spanned<Value> { for entry in table.into_values() { if let Some(last_end) = end { let span = Span::new(last_end, entry.key.start); - commands.push(Command::LayoutSyntaxTree(vec![ - Spanned::new(SyntaxNode::Spacing, span) - ])); + commands.push(Command::LayoutSyntaxTree(vec![Spanned::new( + SyntaxNode::Spacing, + span, + )])); } end = Some(entry.val.span.end); @@ -90,14 +91,10 @@ impl Spanned<Value> { } // Format with debug. - val => vec![ - Command::LayoutSyntaxTree(vec![ - Spanned::new( - SyntaxNode::Text(format!("{:?}", val)), - self.span, - ) - ]) - ], + val => vec![Command::LayoutSyntaxTree(vec![Spanned::new( + SyntaxNode::Text(format!("{:?}", val)), + self.span, + )])], } } } @@ -149,9 +146,8 @@ impl PartialEq for Value { /// layouting engine to do what the function pleases. /// /// The dynamic function object is wrapped in an `Rc` to keep `Value` clonable. -pub type FuncValue = Rc< - dyn Fn(Span, TableValue, LayoutContext<'_>) -> DynFuture<Pass<Value>> ->; +pub type FuncValue = + Rc<dyn Fn(Span, TableValue, LayoutContext<'_>) -> DynFuture<Pass<Value>>>; /// A table of values. /// @@ -500,7 +496,10 @@ mod tests { table.expect::<String>("", Span::ZERO, &mut f), Some("hi".to_string()) ); - assert_eq!(f.diagnostics, [error!(Span::ZERO, "expected string, found bool")]); + assert_eq!(f.diagnostics, [error!( + Span::ZERO, + "expected string, found bool" + )]); assert_eq!(table.len(), 1); } @@ -512,7 +511,10 @@ mod tests { table.insert("hi", entry(Value::Bool(true))); assert_eq!(table.take::<bool>(), Some(false)); assert_eq!(table.take_key::<f64>("hi", &mut f), None); - assert_eq!(f.diagnostics, [error!(Span::ZERO, "expected number, found bool")]); + assert_eq!(f.diagnostics, [error!( + Span::ZERO, + "expected number, found bool" + )]); assert!(table.is_empty()); } @@ -522,10 +524,10 @@ mod tests { table.insert(1, entry(Value::Bool(false))); table.insert(3, entry(Value::Number(0.0))); table.insert(7, entry(Value::Bool(true))); - assert_eq!( - table.take_all_num::<bool>().collect::<Vec<_>>(), - [(1, false), (7, true)], - ); + assert_eq!(table.take_all_num::<bool>().collect::<Vec<_>>(), [ + (1, false), + (7, true) + ],); assert_eq!(table.len(), 1); assert_eq!(table[3].val.v, Value::Number(0.0)); } |
