diff options
Diffstat (limited to 'crates/typst-library/src/model')
| -rw-r--r-- | crates/typst-library/src/model/bibliography.rs | 9 | ||||
| -rw-r--r-- | crates/typst-library/src/model/figure.rs | 17 | ||||
| -rw-r--r-- | crates/typst-library/src/model/footnote.rs | 15 | ||||
| -rw-r--r-- | crates/typst-library/src/model/heading.rs | 4 | ||||
| -rw-r--r-- | crates/typst-library/src/model/link.rs | 7 | ||||
| -rw-r--r-- | crates/typst-library/src/model/outline.rs | 13 | ||||
| -rw-r--r-- | crates/typst-library/src/model/quote.rs | 2 | ||||
| -rw-r--r-- | crates/typst-library/src/model/reference.rs | 14 | ||||
| -rw-r--r-- | crates/typst-library/src/model/table.rs | 2 | ||||
| -rw-r--r-- | crates/typst-library/src/model/terms.rs | 6 |
10 files changed, 41 insertions, 48 deletions
diff --git a/crates/typst-library/src/model/bibliography.rs b/crates/typst-library/src/model/bibliography.rs index 4ab4ff22..95db8a22 100644 --- a/crates/typst-library/src/model/bibliography.rs +++ b/crates/typst-library/src/model/bibliography.rs @@ -638,7 +638,7 @@ impl<'a> Generator<'a> { for elem in &self.groups { let group = elem.to_packed::<CiteGroup>().unwrap(); let location = elem.location().unwrap(); - let children = group.children(); + let children = &group.children; // Groups should never be empty. let Some(first) = children.first() else { continue }; @@ -650,12 +650,11 @@ impl<'a> Generator<'a> { // Create infos and items for each child in the group. for child in children { - let key = *child.key(); - let Some(entry) = database.get(key) else { + let Some(entry) = database.get(child.key) else { errors.push(error!( child.span(), "key `{}` does not exist in the bibliography", - key.resolve() + child.key.resolve() )); continue; }; @@ -682,7 +681,7 @@ impl<'a> Generator<'a> { }; normal &= special_form.is_none(); - subinfos.push(CiteInfo { key, supplement, hidden }); + subinfos.push(CiteInfo { key: child.key, supplement, hidden }); items.push(CitationItem::new(entry, locator, None, hidden, special_form)); } diff --git a/crates/typst-library/src/model/figure.rs b/crates/typst-library/src/model/figure.rs index fd843ee5..52dca966 100644 --- a/crates/typst-library/src/model/figure.rs +++ b/crates/typst-library/src/model/figure.rs @@ -257,7 +257,7 @@ impl Synthesize for Packed<FigureElem> { // Determine the figure's kind. let kind = elem.kind(styles).unwrap_or_else(|| { - elem.body() + elem.body .query_first(&Selector::can::<dyn Figurable>()) .map(|elem| FigureKind::Elem(elem.func())) .unwrap_or_else(|| FigureKind::Elem(ImageElem::elem())) @@ -288,14 +288,13 @@ impl Synthesize for Packed<FigureElem> { // Resolve the supplement with the first descendant of the kind or // just the body, if none was found. let descendant = match kind { - FigureKind::Elem(func) => elem - .body() - .query_first(&Selector::Elem(func, None)) - .map(Cow::Owned), + FigureKind::Elem(func) => { + elem.body.query_first(&Selector::Elem(func, None)).map(Cow::Owned) + } FigureKind::Name(_) => None, }; - let target = descendant.unwrap_or_else(|| Cow::Borrowed(elem.body())); + let target = descendant.unwrap_or_else(|| Cow::Borrowed(&elem.body)); Some(supplement.resolve(engine, styles, [target])?) } }; @@ -437,7 +436,7 @@ impl Outlinable for Packed<FigureElem> { return Ok(None); }; - let mut realized = caption.body().clone(); + let mut realized = caption.body.clone(); if let ( Smart::Custom(Some(Supplement::Content(mut supplement))), Some(Some(counter)), @@ -460,7 +459,7 @@ impl Outlinable for Packed<FigureElem> { let separator = caption.get_separator(StyleChain::default()); - realized = supplement + numbers + separator + caption.body(); + realized = supplement + numbers + separator + caption.body.clone(); } Ok(Some(realized)) @@ -604,7 +603,7 @@ impl Synthesize for Packed<FigureCaption> { impl Show for Packed<FigureCaption> { #[typst_macros::time(name = "figure.caption", span = self.span())] fn show(&self, engine: &mut Engine, styles: StyleChain) -> SourceResult<Content> { - let mut realized = self.body().clone(); + let mut realized = self.body.clone(); if let ( Some(Some(mut supplement)), diff --git a/crates/typst-library/src/model/footnote.rs b/crates/typst-library/src/model/footnote.rs index ffc78ea0..f3b2a19e 100644 --- a/crates/typst-library/src/model/footnote.rs +++ b/crates/typst-library/src/model/footnote.rs @@ -105,12 +105,12 @@ impl FootnoteElem { /// Tests if this footnote is a reference to another footnote. pub fn is_ref(&self) -> bool { - matches!(self.body(), FootnoteBody::Reference(_)) + matches!(self.body, FootnoteBody::Reference(_)) } /// Returns the content of the body of this footnote if it is not a ref. pub fn body_content(&self) -> Option<&Content> { - match self.body() { + match &self.body { FootnoteBody::Content(content) => Some(content), _ => None, } @@ -120,9 +120,9 @@ impl FootnoteElem { impl Packed<FootnoteElem> { /// Returns the location of the definition of this footnote. pub fn declaration_location(&self, engine: &Engine) -> StrResult<Location> { - match self.body() { + match self.body { FootnoteBody::Reference(label) => { - let element = engine.introspector.query_label(*label)?; + let element = engine.introspector.query_label(label)?; let footnote = element .to_packed::<FootnoteElem>() .ok_or("referenced element should be a footnote")?; @@ -281,12 +281,11 @@ impl Show for Packed<FootnoteEntry> { #[typst_macros::time(name = "footnote.entry", span = self.span())] fn show(&self, engine: &mut Engine, styles: StyleChain) -> SourceResult<Content> { let span = self.span(); - let note = self.note(); let number_gap = Em::new(0.05); let default = StyleChain::default(); - let numbering = note.numbering(default); + let numbering = self.note.numbering(default); let counter = Counter::of(FootnoteElem::elem()); - let Some(loc) = note.location() else { + let Some(loc) = self.note.location() else { bail!( span, "footnote entry must have a location"; hint: "try using a query or a show rule to customize the footnote instead" @@ -304,7 +303,7 @@ impl Show for Packed<FootnoteEntry> { HElem::new(self.indent(styles).into()).pack(), sup, HElem::new(number_gap.into()).with_weak(true).pack(), - note.body_content().unwrap().clone(), + self.note.body_content().unwrap().clone(), ])) } } diff --git a/crates/typst-library/src/model/heading.rs b/crates/typst-library/src/model/heading.rs index ec9cf4e9..db131afe 100644 --- a/crates/typst-library/src/model/heading.rs +++ b/crates/typst-library/src/model/heading.rs @@ -223,7 +223,7 @@ impl Show for Packed<HeadingElem> { const SPACING_TO_NUMBERING: Em = Em::new(0.3); let span = self.span(); - let mut realized = self.body().clone(); + let mut realized = self.body.clone(); let hanging_indent = self.hanging_indent(styles); let mut indent = match hanging_indent { @@ -360,7 +360,7 @@ impl Outlinable for Packed<HeadingElem> { return Ok(None); } - let mut content = self.body().clone(); + let mut content = self.body.clone(); if let Some(numbering) = (**self).numbering(StyleChain::default()).as_ref() { let numbers = Counter::of(HeadingElem::elem()).display_at_loc( engine, diff --git a/crates/typst-library/src/model/link.rs b/crates/typst-library/src/model/link.rs index bbc47da0..4558cb39 100644 --- a/crates/typst-library/src/model/link.rs +++ b/crates/typst-library/src/model/link.rs @@ -102,11 +102,10 @@ impl LinkElem { impl Show for Packed<LinkElem> { #[typst_macros::time(name = "link", span = self.span())] fn show(&self, engine: &mut Engine, styles: StyleChain) -> SourceResult<Content> { - let body = self.body().clone(); - let dest = self.dest(); + let body = self.body.clone(); Ok(if TargetElem::target_in(styles).is_html() { - if let LinkTarget::Dest(Destination::Url(url)) = dest { + if let LinkTarget::Dest(Destination::Url(url)) = &self.dest { HtmlElem::new(tag::a) .with_attr(attr::href, url.clone().into_inner()) .with_body(Some(body)) @@ -120,7 +119,7 @@ impl Show for Packed<LinkElem> { body } } else { - let linked = match self.dest() { + let linked = match &self.dest { LinkTarget::Dest(dest) => body.linked(dest.clone()), LinkTarget::Label(label) => { let elem = engine.introspector.query_label(*label).at(self.span())?; diff --git a/crates/typst-library/src/model/outline.rs b/crates/typst-library/src/model/outline.rs index e8d32a54..84661c1c 100644 --- a/crates/typst-library/src/model/outline.rs +++ b/crates/typst-library/src/model/outline.rs @@ -219,8 +219,7 @@ impl Show for Packed<OutlineElem> { continue; }; - let level = entry.level(); - if depth < *level { + if depth < entry.level { continue; } @@ -229,7 +228,7 @@ impl Show for Packed<OutlineElem> { while ancestors .last() .and_then(|ancestor| ancestor.with::<dyn Outlinable>()) - .is_some_and(|last| last.level() >= *level) + .is_some_and(|last| last.level() >= entry.level) { ancestors.pop(); } @@ -483,7 +482,7 @@ impl Show for Packed<OutlineEntry> { #[typst_macros::time(name = "outline.entry", span = self.span())] fn show(&self, _: &mut Engine, styles: StyleChain) -> SourceResult<Content> { let mut seq = vec![]; - let elem = self.element(); + let elem = &self.element; // In case a user constructs an outline entry with an arbitrary element. let Some(location) = elem.location() else { @@ -512,7 +511,7 @@ impl Show for Packed<OutlineEntry> { seq.push(TextElem::packed("\u{202B}")); } - seq.push(self.body().clone().linked(Destination::Location(location))); + seq.push(self.body.clone().linked(Destination::Location(location))); if rtl { // "Pop Directional Formatting" @@ -520,7 +519,7 @@ impl Show for Packed<OutlineEntry> { } // Add filler symbols between the section name and page number. - if let Some(filler) = self.fill() { + if let Some(filler) = &self.fill { seq.push(SpaceElem::shared().clone()); seq.push( BoxElem::new() @@ -535,7 +534,7 @@ impl Show for Packed<OutlineEntry> { } // Add the page number. - let page = self.page().clone().linked(Destination::Location(location)); + let page = self.page.clone().linked(Destination::Location(location)); seq.push(page); Ok(Content::sequence(seq)) diff --git a/crates/typst-library/src/model/quote.rs b/crates/typst-library/src/model/quote.rs index 110825f1..2eaa32d4 100644 --- a/crates/typst-library/src/model/quote.rs +++ b/crates/typst-library/src/model/quote.rs @@ -156,7 +156,7 @@ cast! { impl Show for Packed<QuoteElem> { #[typst_macros::time(name = "quote", span = self.span())] fn show(&self, _: &mut Engine, styles: StyleChain) -> SourceResult<Content> { - let mut realized = self.body().clone(); + let mut realized = self.body.clone(); let block = self.block(styles); if self.quotes(styles) == Smart::Custom(true) || !block { diff --git a/crates/typst-library/src/model/reference.rs b/crates/typst-library/src/model/reference.rs index 96aa2117..31661768 100644 --- a/crates/typst-library/src/model/reference.rs +++ b/crates/typst-library/src/model/reference.rs @@ -182,9 +182,8 @@ impl Synthesize for Packed<RefElem> { elem.push_citation(Some(citation)); elem.push_element(None); - let target = *elem.target(); - if !BibliographyElem::has(engine, target) { - if let Ok(found) = engine.introspector.query_label(target).cloned() { + if !BibliographyElem::has(engine, elem.target) { + if let Ok(found) = engine.introspector.query_label(elem.target).cloned() { elem.push_element(Some(found)); return Ok(()); } @@ -197,8 +196,7 @@ impl Synthesize for Packed<RefElem> { impl Show for Packed<RefElem> { #[typst_macros::time(name = "ref", span = self.span())] fn show(&self, engine: &mut Engine, styles: StyleChain) -> SourceResult<Content> { - let target = *self.target(); - let elem = engine.introspector.query_label(target); + let elem = engine.introspector.query_label(self.target); let span = self.span(); let form = self.form(styles); @@ -229,7 +227,7 @@ impl Show for Packed<RefElem> { } // RefForm::Normal - if BibliographyElem::has(engine, target) { + if BibliographyElem::has(engine, self.target) { if elem.is_ok() { bail!(span, "label occurs in the document and its bibliography"); } @@ -240,7 +238,7 @@ impl Show for Packed<RefElem> { let elem = elem.at(span)?; if let Some(footnote) = elem.to_packed::<FootnoteElem>() { - return Ok(footnote.into_ref(target).pack().spanned(span)); + return Ok(footnote.into_ref(self.target).pack().spanned(span)); } let elem = elem.clone(); @@ -319,7 +317,7 @@ fn to_citation( engine: &mut Engine, styles: StyleChain, ) -> SourceResult<Packed<CiteElem>> { - let mut elem = Packed::new(CiteElem::new(*reference.target()).with_supplement( + let mut elem = Packed::new(CiteElem::new(reference.target).with_supplement( match reference.supplement(styles).clone() { Smart::Custom(Some(Supplement::Content(content))) => Some(content), _ => None, diff --git a/crates/typst-library/src/model/table.rs b/crates/typst-library/src/model/table.rs index 7dfaf45d..fa44cb58 100644 --- a/crates/typst-library/src/model/table.rs +++ b/crates/typst-library/src/model/table.rs @@ -706,7 +706,7 @@ cast! { impl Show for Packed<TableCell> { fn show(&self, _engine: &mut Engine, styles: StyleChain) -> SourceResult<Content> { - show_grid_cell(self.body().clone(), self.inset(styles), self.align(styles)) + show_grid_cell(self.body.clone(), self.inset(styles), self.align(styles)) } } diff --git a/crates/typst-library/src/model/terms.rs b/crates/typst-library/src/model/terms.rs index 13aa8c6d..1261ea4f 100644 --- a/crates/typst-library/src/model/terms.rs +++ b/crates/typst-library/src/model/terms.rs @@ -151,12 +151,12 @@ impl Show for Packed<TermsElem> { .then(|| HElem::new((-hanging_indent).into()).pack().spanned(span)); let mut children = vec![]; - for child in self.children().iter() { + for child in self.children.iter() { let mut seq = vec![]; seq.extend(unpad.clone()); - seq.push(child.term().clone().strong()); + seq.push(child.term.clone().strong()); seq.push((*separator).clone()); - seq.push(child.description().clone()); + seq.push(child.description.clone()); children.push(StackChild::Block(Content::sequence(seq))); } |
