diff options
| author | Laurenz <laurmaedje@gmail.com> | 2021-01-13 21:33:22 +0100 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2021-01-13 21:33:22 +0100 |
| commit | 1b53e27f270e3c040ee095573af9a5243980191a (patch) | |
| tree | 3ed3e3d17b35cb04ded50a38331438468b61063e /src | |
| parent | c36a136e6f26ac99e58465ad072c282fe6dbaedf (diff) | |
Some minor improvements ♻
Diffstat (limited to 'src')
| -rw-r--r-- | src/eval/call.rs | 2 | ||||
| -rw-r--r-- | src/geom/length.rs | 5 | ||||
| -rw-r--r-- | src/geom/size.rs | 5 | ||||
| -rw-r--r-- | src/layout/mod.rs | 5 | ||||
| -rw-r--r-- | src/parse/lines.rs | 8 | ||||
| -rw-r--r-- | src/pretty.rs | 3 |
6 files changed, 21 insertions, 7 deletions
diff --git a/src/eval/call.rs b/src/eval/call.rs index a2387a17..f47ee847 100644 --- a/src/eval/call.rs +++ b/src/eval/call.rs @@ -102,7 +102,7 @@ impl Args { /// Convert and remove the value for the given named argument, producing an /// error if the conversion fails. - pub fn get<'a, T>(&mut self, ctx: &mut EvalContext, name: &str) -> Option<T> + pub fn get<T>(&mut self, ctx: &mut EvalContext, name: &str) -> Option<T> where T: Cast<Spanned<Value>>, { diff --git a/src/geom/length.rs b/src/geom/length.rs index 3e6c8601..f4d8682e 100644 --- a/src/geom/length.rs +++ b/src/geom/length.rs @@ -80,6 +80,11 @@ impl Length { pub fn max(self, other: Self) -> Self { Self { raw: self.raw.max(other.raw) } } + + /// Whether the length is `NaN`. + pub fn is_nan(self) -> bool { + self.raw.is_nan() + } } impl Display for Length { diff --git a/src/geom/size.rs b/src/geom/size.rs index bc233e5c..1dfc8b97 100644 --- a/src/geom/size.rs +++ b/src/geom/size.rs @@ -30,6 +30,11 @@ impl Size { pub fn fits(self, other: Self) -> bool { self.width >= other.width && self.height >= other.height } + + /// Whether any of the two components is `NaN`. + pub fn is_nan(self) -> bool { + self.width.is_nan() || self.height.is_nan() + } } impl Get<SpecAxis> for Size { diff --git a/src/layout/mod.rs b/src/layout/mod.rs index d09566e3..30026b9f 100644 --- a/src/layout/mod.rs +++ b/src/layout/mod.rs @@ -128,7 +128,10 @@ impl Areas { /// /// If this is false calling `next()` will have no effect. pub fn in_full_last(&self) -> bool { - self.backlog.is_empty() && self.last.map_or(true, |size| self.current.rem == size) + self.backlog.is_empty() + && self.last.map_or(true, |size| { + self.current.rem.is_nan() || size.is_nan() || self.current.rem == size + }) } } diff --git a/src/parse/lines.rs b/src/parse/lines.rs index d1a6c781..c47b7534 100644 --- a/src/parse/lines.rs +++ b/src/parse/lines.rs @@ -70,13 +70,13 @@ impl<'s> LineMap<'s> { /// Whether this character denotes a newline. pub fn is_newline(character: char) -> bool { - match character { + matches!( + character, // Line Feed, Vertical Tab, Form Feed, Carriage Return. '\n' | '\x0B' | '\x0C' | '\r' | // Next Line, Line Separator, Paragraph Separator. - '\u{0085}' | '\u{2028}' | '\u{2029}' => true, - _ => false, - } + '\u{0085}' | '\u{2028}' | '\u{2029}' + ) } #[cfg(test)] diff --git a/src/pretty.rs b/src/pretty.rs index f6398495..f1c3cfb7 100644 --- a/src/pretty.rs +++ b/src/pretty.rs @@ -63,6 +63,7 @@ impl Printer { impl Write for Printer { fn write_str(&mut self, s: &str) -> Result { - Ok(self.push_str(s)) + self.push_str(s); + Ok(()) } } |
