From 2a92428ff6986d8e564b7c223f3d0c5ca0eacaf1 Mon Sep 17 00:00:00 2001 From: Laurenz Date: Thu, 27 Aug 2020 21:47:26 +0200 Subject: [PATCH] =?UTF-8?q?Do=20as=20Dolores=20says=20=E2=9A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/compute/value.rs | 6 ++---- src/export/pdf.rs | 10 +++++----- src/syntax/parsing.rs | 14 +++++++------- src/syntax/tokens.rs | 2 +- 4 files changed, 15 insertions(+), 17 deletions(-) diff --git a/src/compute/value.rs b/src/compute/value.rs index c11a3d316..bac6396dd 100644 --- a/src/compute/value.rs +++ b/src/compute/value.rs @@ -132,9 +132,7 @@ impl PartialEq for Value { (Color(a), Color(b)) => a == b, (Table(a), Table(b)) => a == b, (Tree(a), Tree(b)) => a == b, - (Func(a), Func(b)) => { - a.as_ref() as *const _ == b.as_ref() as *const _ - } + (Func(a), Func(b)) => Rc::ptr_eq(a, b), (Commands(a), Commands(b)) => a == b, _ => false, } @@ -202,7 +200,7 @@ impl TableValue { /// there is any. /// /// Generates an error if the key exists but the value does not match. - pub fn take_key<'a, T>(&mut self, key: &str, f: &mut Feedback) -> Option + pub fn take_key(&mut self, key: &str, f: &mut Feedback) -> Option where T: TryFromValue, { diff --git a/src/export/pdf.rs b/src/export/pdf.rs index cd417a9cf..e8220b546 100644 --- a/src/export/pdf.rs +++ b/src/export/pdf.rs @@ -14,7 +14,7 @@ use tide::{PdfWriter, Rect, Ref, Trailer, Version}; use ttf_parser::{name_id, GlyphId}; use crate::layout::elements::LayoutElement; -use crate::layout::{BoxLayout, MultiLayout}; +use crate::layout::BoxLayout; use crate::length::Length; use crate::SharedFontLoader; @@ -27,7 +27,7 @@ use crate::SharedFontLoader; /// The raw _PDF_ is written into the `target` writable, returning the number of /// bytes written. pub fn export( - layout: &MultiLayout, + layout: &[BoxLayout], loader: &SharedFontLoader, target: W, ) -> io::Result { @@ -36,7 +36,7 @@ pub fn export( struct PdfExporter<'a, W: Write> { writer: PdfWriter, - layouts: &'a MultiLayout, + layouts: &'a [BoxLayout], loader: &'a SharedFontLoader, /// We need to know exactly which indirect reference id will be used for /// which objects up-front to correctly declare the document catalogue, page @@ -60,7 +60,7 @@ const NUM_OBJECTS_PER_FONT: u32 = 5; impl<'a, W: Write> PdfExporter<'a, W> { fn new( - layouts: &'a MultiLayout, + layouts: &'a [BoxLayout], loader: &'a SharedFontLoader, target: W, ) -> io::Result { @@ -289,7 +289,7 @@ impl<'a, W: Write> PdfExporter<'a, W> { /// Assigns a new PDF-internal index to each used face and returns two mappings: /// - Forwards from the old face ids to the new pdf indices (hash map) /// - Backwards from the pdf indices to the old face ids (vec) -fn remap_fonts(layouts: &MultiLayout) -> (HashMap, Vec) { +fn remap_fonts(layouts: &[BoxLayout]) -> (HashMap, Vec) { let mut to_pdf = HashMap::new(); let mut to_layout = vec![]; diff --git a/src/syntax/parsing.rs b/src/syntax/parsing.rs index 96db687db..29a9d788f 100644 --- a/src/syntax/parsing.rs +++ b/src/syntax/parsing.rs @@ -67,7 +67,7 @@ impl Parser<'_> { } Token::LeftBracket => { - self.parse_bracket_call(false).map(|c| SyntaxNode::Call(c)) + self.parse_bracket_call(false).map(SyntaxNode::Call) } Token::Star => self.with_span(SyntaxNode::ToggleBolder), @@ -143,7 +143,7 @@ impl Parser<'_> { let (has_chained_child, end) = if self.peek().is_some() { let item = self.parse_bracket_call(true); let span = item.span; - let t = vec![item.map(|f| SyntaxNode::Call(f))]; + let t = vec![item.map(SyntaxNode::Call)]; args.push(SpannedEntry::val(Spanned::new(Expr::Tree(t), span))); (true, span.end) } else { @@ -203,10 +203,10 @@ impl Parser<'_> { Some(Token::LeftParen) => { let call = self.parse_paren_call(ident); - (None, call.map(|c| Expr::Call(c))) + (None, call.map(Expr::Call)) } - _ => (None, ident.map(|id| Expr::Ident(id))) + _ => (None, ident.map(Expr::Ident)) } } else { (None, try_or!(self.parse_expr(), { @@ -316,9 +316,9 @@ impl Parser<'_> { self.eat(); self.skip_white(); if self.check(Token::LeftParen) { - self.parse_paren_call(name).map(|call| Expr::Call(call)) + self.parse_paren_call(name).map(Expr::Call) } else { - name.map(|id| Expr::Ident(id)) + name.map(Expr::Ident) } } @@ -377,7 +377,7 @@ impl Parser<'_> { // This is a bracketed function call. Token::LeftBracket => { let call = self.parse_bracket_call(false); - let tree = vec![call.map(|c| SyntaxNode::Call(c))]; + let tree = vec![call.map(SyntaxNode::Call)]; Spanned::new(Expr::Tree(tree), span) } diff --git a/src/syntax/tokens.rs b/src/syntax/tokens.rs index 24d8ecfb5..1dcf9022e 100644 --- a/src/syntax/tokens.rs +++ b/src/syntax/tokens.rs @@ -478,7 +478,7 @@ pub fn is_identifier(string: &str) -> bool { _ => return false, } - while let Some(c) = chars.next() { + for c in chars { match c { c if UnicodeXID::is_xid_continue(c) || is_extra_allowed(c) => {} _ => return false,