Don't generate accessors for required fields (#5680)

This commit is contained in:
Laurenz 2025-01-10 17:54:11 +01:00 committed by GitHub
parent 9473aface1
commit 6b9b78596a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
44 changed files with 137 additions and 144 deletions

View File

@ -161,9 +161,9 @@ pub fn collect<'a>(
} }
if let Some(case) = TextElem::case_in(styles) { if let Some(case) = TextElem::case_in(styles) {
full.push_str(&case.apply(elem.text())); full.push_str(&case.apply(&elem.text));
} else { } else {
full.push_str(elem.text()); full.push_str(&elem.text);
} }
if dir != outer_dir { if dir != outer_dir {
@ -172,13 +172,12 @@ pub fn collect<'a>(
} }
}); });
} else if let Some(elem) = child.to_packed::<HElem>() { } else if let Some(elem) = child.to_packed::<HElem>() {
let amount = elem.amount(); if elem.amount.is_zero() {
if amount.is_zero() {
continue; continue;
} }
collector.push_item(match amount { collector.push_item(match elem.amount {
Spacing::Fr(fr) => Item::Fractional(*fr, None), Spacing::Fr(fr) => Item::Fractional(fr, None),
Spacing::Rel(rel) => Item::Absolute( Spacing::Rel(rel) => Item::Absolute(
rel.resolve(styles).relative_to(region.x), rel.resolve(styles).relative_to(region.x),
elem.weak(styles), elem.weak(styles),

View File

@ -40,7 +40,7 @@ pub fn layout_list(
let mut cells = vec![]; let mut cells = vec![];
let mut locator = locator.split(); let mut locator = locator.split();
for item in elem.children() { for item in &elem.children {
cells.push(Cell::new(Content::empty(), locator.next(&()))); cells.push(Cell::new(Content::empty(), locator.next(&())));
cells.push(Cell::new(marker.clone(), locator.next(&marker.span()))); cells.push(Cell::new(marker.clone(), locator.next(&marker.span())));
cells.push(Cell::new(Content::empty(), locator.next(&()))); cells.push(Cell::new(Content::empty(), locator.next(&())));
@ -101,7 +101,7 @@ pub fn layout_enum(
// relation to the item it refers to. // relation to the item it refers to.
let number_align = elem.number_align(styles); let number_align = elem.number_align(styles);
for item in elem.children() { for item in &elem.children {
number = item.number(styles).unwrap_or(number); number = item.number(styles).unwrap_or(number);
let context = Context::new(None, Some(styles)); let context = Context::new(None, Some(styles));

View File

@ -16,7 +16,7 @@ pub fn layout_accent(
styles: StyleChain, styles: StyleChain,
) -> SourceResult<()> { ) -> SourceResult<()> {
let cramped = style_cramped(); let cramped = style_cramped();
let mut base = ctx.layout_into_fragment(elem.base(), styles.chain(&cramped))?; let mut base = ctx.layout_into_fragment(&elem.base, styles.chain(&cramped))?;
// Try to replace a glyph with its dotless variant. // Try to replace a glyph with its dotless variant.
if let MathFragment::Glyph(glyph) = &mut base { if let MathFragment::Glyph(glyph) = &mut base {
@ -29,8 +29,8 @@ pub fn layout_accent(
let width = elem.size(styles).relative_to(base.width()); let width = elem.size(styles).relative_to(base.width());
let Accent(c) = elem.accent(); let Accent(c) = elem.accent;
let mut glyph = GlyphFragment::new(ctx, styles, *c, elem.span()); let mut glyph = GlyphFragment::new(ctx, styles, c, elem.span());
// Try to replace accent glyph with flattened variant. // Try to replace accent glyph with flattened variant.
let flattened_base_height = scaled!(ctx, styles, flattened_accent_base_height); let flattened_base_height = scaled!(ctx, styles, flattened_accent_base_height);

View File

@ -29,7 +29,7 @@ pub fn layout_attach(
let elem = merged.as_ref().unwrap_or(elem); let elem = merged.as_ref().unwrap_or(elem);
let stretch = stretch_size(styles, elem); let stretch = stretch_size(styles, elem);
let mut base = ctx.layout_into_fragment(elem.base(), styles)?; let mut base = ctx.layout_into_fragment(&elem.base, styles)?;
let sup_style = style_for_superscript(styles); let sup_style = style_for_superscript(styles);
let sup_style_chain = styles.chain(&sup_style); let sup_style_chain = styles.chain(&sup_style);
let tl = elem.tl(sup_style_chain); let tl = elem.tl(sup_style_chain);
@ -95,7 +95,7 @@ pub fn layout_primes(
ctx: &mut MathContext, ctx: &mut MathContext,
styles: StyleChain, styles: StyleChain,
) -> SourceResult<()> { ) -> SourceResult<()> {
match *elem.count() { match elem.count {
count @ 1..=4 => { count @ 1..=4 => {
let c = match count { let c = match count {
1 => '', 1 => '',
@ -134,7 +134,7 @@ pub fn layout_scripts(
ctx: &mut MathContext, ctx: &mut MathContext,
styles: StyleChain, styles: StyleChain,
) -> SourceResult<()> { ) -> SourceResult<()> {
let mut fragment = ctx.layout_into_fragment(elem.body(), styles)?; let mut fragment = ctx.layout_into_fragment(&elem.body, styles)?;
fragment.set_limits(Limits::Never); fragment.set_limits(Limits::Never);
ctx.push(fragment); ctx.push(fragment);
Ok(()) Ok(())
@ -148,7 +148,7 @@ pub fn layout_limits(
styles: StyleChain, styles: StyleChain,
) -> SourceResult<()> { ) -> SourceResult<()> {
let limits = if elem.inline(styles) { Limits::Always } else { Limits::Display }; let limits = if elem.inline(styles) { Limits::Always } else { Limits::Display };
let mut fragment = ctx.layout_into_fragment(elem.body(), styles)?; let mut fragment = ctx.layout_into_fragment(&elem.body, styles)?;
fragment.set_limits(limits); fragment.set_limits(limits);
ctx.push(fragment); ctx.push(fragment);
Ok(()) Ok(())
@ -157,9 +157,9 @@ pub fn layout_limits(
/// Get the size to stretch the base to. /// Get the size to stretch the base to.
fn stretch_size(styles: StyleChain, elem: &Packed<AttachElem>) -> Option<Rel<Abs>> { fn stretch_size(styles: StyleChain, elem: &Packed<AttachElem>) -> Option<Rel<Abs>> {
// Extract from an EquationElem. // Extract from an EquationElem.
let mut base = elem.base(); let mut base = &elem.base;
while let Some(equation) = base.to_packed::<EquationElem>() { while let Some(equation) = base.to_packed::<EquationElem>() {
base = equation.body(); base = &equation.body;
} }
base.to_packed::<StretchElem>().map(|stretch| stretch.size(styles)) base.to_packed::<StretchElem>().map(|stretch| stretch.size(styles))

View File

@ -16,7 +16,7 @@ pub fn layout_cancel(
ctx: &mut MathContext, ctx: &mut MathContext,
styles: StyleChain, styles: StyleChain,
) -> SourceResult<()> { ) -> SourceResult<()> {
let body = ctx.layout_into_fragment(elem.body(), styles)?; let body = ctx.layout_into_fragment(&elem.body, styles)?;
// Preserve properties of body. // Preserve properties of body.
let body_class = body.class(); let body_class = body.class();

View File

@ -23,8 +23,8 @@ pub fn layout_frac(
layout_frac_like( layout_frac_like(
ctx, ctx,
styles, styles,
elem.num(), &elem.num,
std::slice::from_ref(elem.denom()), std::slice::from_ref(&elem.denom),
false, false,
elem.span(), elem.span(),
) )
@ -37,7 +37,7 @@ pub fn layout_binom(
ctx: &mut MathContext, ctx: &mut MathContext,
styles: StyleChain, styles: StyleChain,
) -> SourceResult<()> { ) -> SourceResult<()> {
layout_frac_like(ctx, styles, elem.upper(), elem.lower(), true, elem.span()) layout_frac_like(ctx, styles, &elem.upper, &elem.lower, true, elem.span())
} }
/// Layout a fraction or binomial. /// Layout a fraction or binomial.

View File

@ -13,17 +13,16 @@ pub fn layout_lr(
ctx: &mut MathContext, ctx: &mut MathContext,
styles: StyleChain, styles: StyleChain,
) -> SourceResult<()> { ) -> SourceResult<()> {
let mut body = elem.body();
// Extract from an EquationElem. // Extract from an EquationElem.
let mut body = &elem.body;
if let Some(equation) = body.to_packed::<EquationElem>() { if let Some(equation) = body.to_packed::<EquationElem>() {
body = equation.body(); body = &equation.body;
} }
// Extract implicit LrElem. // Extract implicit LrElem.
if let Some(lr) = body.to_packed::<LrElem>() { if let Some(lr) = body.to_packed::<LrElem>() {
if lr.size(styles).is_one() { if lr.size(styles).is_one() {
body = lr.body(); body = &lr.body;
} }
} }
@ -100,7 +99,7 @@ pub fn layout_mid(
ctx: &mut MathContext, ctx: &mut MathContext,
styles: StyleChain, styles: StyleChain,
) -> SourceResult<()> { ) -> SourceResult<()> {
let mut fragments = ctx.layout_into_fragments(elem.body(), styles)?; let mut fragments = ctx.layout_into_fragments(&elem.body, styles)?;
for fragment in &mut fragments { for fragment in &mut fragments {
match fragment { match fragment {

View File

@ -27,7 +27,7 @@ pub fn layout_vec(
let frame = layout_vec_body( let frame = layout_vec_body(
ctx, ctx,
styles, styles,
elem.children(), &elem.children,
elem.align(styles), elem.align(styles),
elem.gap(styles), elem.gap(styles),
LeftRightAlternator::Right, LeftRightAlternator::Right,
@ -44,7 +44,7 @@ pub fn layout_mat(
styles: StyleChain, styles: StyleChain,
) -> SourceResult<()> { ) -> SourceResult<()> {
let augment = elem.augment(styles); let augment = elem.augment(styles);
let rows = elem.rows(); let rows = &elem.rows;
if let Some(aug) = &augment { if let Some(aug) = &augment {
for &offset in &aug.hline.0 { for &offset in &aug.hline.0 {
@ -58,7 +58,7 @@ pub fn layout_mat(
} }
} }
let ncols = elem.rows().first().map_or(0, |row| row.len()); let ncols = rows.first().map_or(0, |row| row.len());
for &offset in &aug.vline.0 { for &offset in &aug.vline.0 {
if offset == 0 || offset.unsigned_abs() >= ncols { if offset == 0 || offset.unsigned_abs() >= ncols {
@ -97,7 +97,7 @@ pub fn layout_cases(
let frame = layout_vec_body( let frame = layout_vec_body(
ctx, ctx,
styles, styles,
elem.children(), &elem.children,
FixedAlignment::Start, FixedAlignment::Start,
elem.gap(styles), elem.gap(styles),
LeftRightAlternator::None, LeftRightAlternator::None,

View File

@ -632,7 +632,7 @@ fn layout_h(
ctx: &mut MathContext, ctx: &mut MathContext,
styles: StyleChain, styles: StyleChain,
) -> SourceResult<()> { ) -> SourceResult<()> {
if let Spacing::Rel(rel) = elem.amount() { if let Spacing::Rel(rel) = elem.amount {
if rel.rel.is_zero() { if rel.rel.is_zero() {
ctx.push(MathFragment::Spacing(rel.abs.resolve(styles), elem.weak(styles))); ctx.push(MathFragment::Spacing(rel.abs.resolve(styles), elem.weak(styles)));
} }
@ -647,11 +647,10 @@ fn layout_class(
ctx: &mut MathContext, ctx: &mut MathContext,
styles: StyleChain, styles: StyleChain,
) -> SourceResult<()> { ) -> SourceResult<()> {
let class = *elem.class(); let style = EquationElem::set_class(Some(elem.class)).wrap();
let style = EquationElem::set_class(Some(class)).wrap(); let mut fragment = ctx.layout_into_fragment(&elem.body, styles.chain(&style))?;
let mut fragment = ctx.layout_into_fragment(elem.body(), styles.chain(&style))?; fragment.set_class(elem.class);
fragment.set_class(class); fragment.set_limits(Limits::for_class(elem.class));
fragment.set_limits(Limits::for_class(class));
ctx.push(fragment); ctx.push(fragment);
Ok(()) Ok(())
} }
@ -663,7 +662,7 @@ fn layout_op(
ctx: &mut MathContext, ctx: &mut MathContext,
styles: StyleChain, styles: StyleChain,
) -> SourceResult<()> { ) -> SourceResult<()> {
let fragment = ctx.layout_into_fragment(elem.text(), styles)?; let fragment = ctx.layout_into_fragment(&elem.text, styles)?;
let italics = fragment.italics_correction(); let italics = fragment.italics_correction();
let accent_attach = fragment.accent_attach(); let accent_attach = fragment.accent_attach();
let text_like = fragment.is_text_like(); let text_like = fragment.is_text_like();

View File

@ -18,7 +18,6 @@ pub fn layout_root(
styles: StyleChain, styles: StyleChain,
) -> SourceResult<()> { ) -> SourceResult<()> {
let index = elem.index(styles); let index = elem.index(styles);
let radicand = elem.radicand();
let span = elem.span(); let span = elem.span();
let gap = scaled!( let gap = scaled!(
@ -36,7 +35,7 @@ pub fn layout_root(
let radicand = { let radicand = {
let cramped = style_cramped(); let cramped = style_cramped();
let styles = styles.chain(&cramped); let styles = styles.chain(&cramped);
let run = ctx.layout_into_run(radicand, styles)?; let run = ctx.layout_into_run(&elem.radicand, styles)?;
let multiline = run.is_multiline(); let multiline = run.is_multiline();
let mut radicand = run.into_fragment(styles).into_frame(); let mut radicand = run.into_fragment(styles).into_frame();
if multiline { if multiline {

View File

@ -21,7 +21,7 @@ pub fn layout_stretch(
ctx: &mut MathContext, ctx: &mut MathContext,
styles: StyleChain, styles: StyleChain,
) -> SourceResult<()> { ) -> SourceResult<()> {
let mut fragment = ctx.layout_into_fragment(elem.body(), styles)?; let mut fragment = ctx.layout_into_fragment(&elem.body, styles)?;
stretch_fragment( stretch_fragment(
ctx, ctx,
styles, styles,

View File

@ -20,7 +20,7 @@ pub fn layout_text(
ctx: &mut MathContext, ctx: &mut MathContext,
styles: StyleChain, styles: StyleChain,
) -> SourceResult<()> { ) -> SourceResult<()> {
let text = elem.text(); let text = &elem.text;
let span = elem.span(); let span = elem.span();
let mut chars = text.chars(); let mut chars = text.chars();
let math_size = EquationElem::size_in(styles); let math_size = EquationElem::size_in(styles);

View File

@ -32,7 +32,7 @@ pub fn layout_underline(
ctx: &mut MathContext, ctx: &mut MathContext,
styles: StyleChain, styles: StyleChain,
) -> SourceResult<()> { ) -> SourceResult<()> {
layout_underoverline(ctx, styles, elem.body(), elem.span(), Position::Under) layout_underoverline(ctx, styles, &elem.body, elem.span(), Position::Under)
} }
/// Lays out an [`OverlineElem`]. /// Lays out an [`OverlineElem`].
@ -42,7 +42,7 @@ pub fn layout_overline(
ctx: &mut MathContext, ctx: &mut MathContext,
styles: StyleChain, styles: StyleChain,
) -> SourceResult<()> { ) -> SourceResult<()> {
layout_underoverline(ctx, styles, elem.body(), elem.span(), Position::Over) layout_underoverline(ctx, styles, &elem.body, elem.span(), Position::Over)
} }
/// Lays out an [`UnderbraceElem`]. /// Lays out an [`UnderbraceElem`].
@ -55,7 +55,7 @@ pub fn layout_underbrace(
layout_underoverspreader( layout_underoverspreader(
ctx, ctx,
styles, styles,
elem.body(), &elem.body,
&elem.annotation(styles), &elem.annotation(styles),
'⏟', '⏟',
BRACE_GAP, BRACE_GAP,
@ -74,7 +74,7 @@ pub fn layout_overbrace(
layout_underoverspreader( layout_underoverspreader(
ctx, ctx,
styles, styles,
elem.body(), &elem.body,
&elem.annotation(styles), &elem.annotation(styles),
'⏞', '⏞',
BRACE_GAP, BRACE_GAP,
@ -93,7 +93,7 @@ pub fn layout_underbracket(
layout_underoverspreader( layout_underoverspreader(
ctx, ctx,
styles, styles,
elem.body(), &elem.body,
&elem.annotation(styles), &elem.annotation(styles),
'⎵', '⎵',
BRACKET_GAP, BRACKET_GAP,
@ -112,7 +112,7 @@ pub fn layout_overbracket(
layout_underoverspreader( layout_underoverspreader(
ctx, ctx,
styles, styles,
elem.body(), &elem.body,
&elem.annotation(styles), &elem.annotation(styles),
'⎴', '⎴',
BRACKET_GAP, BRACKET_GAP,
@ -131,7 +131,7 @@ pub fn layout_underparen(
layout_underoverspreader( layout_underoverspreader(
ctx, ctx,
styles, styles,
elem.body(), &elem.body,
&elem.annotation(styles), &elem.annotation(styles),
'⏝', '⏝',
PAREN_GAP, PAREN_GAP,
@ -150,7 +150,7 @@ pub fn layout_overparen(
layout_underoverspreader( layout_underoverspreader(
ctx, ctx,
styles, styles,
elem.body(), &elem.body,
&elem.annotation(styles), &elem.annotation(styles),
'⏜', '⏜',
PAREN_GAP, PAREN_GAP,
@ -169,7 +169,7 @@ pub fn layout_undershell(
layout_underoverspreader( layout_underoverspreader(
ctx, ctx,
styles, styles,
elem.body(), &elem.body,
&elem.annotation(styles), &elem.annotation(styles),
'⏡', '⏡',
SHELL_GAP, SHELL_GAP,
@ -188,7 +188,7 @@ pub fn layout_overshell(
layout_underoverspreader( layout_underoverspreader(
ctx, ctx,
styles, styles,
elem.body(), &elem.body,
&elem.annotation(styles), &elem.annotation(styles),
'⏠', '⏠',
SHELL_GAP, SHELL_GAP,

View File

@ -62,7 +62,7 @@ pub fn layout_path(
axes.resolve(styles).zip_map(region.size, Rel::relative_to).to_point() axes.resolve(styles).zip_map(region.size, Rel::relative_to).to_point()
}; };
let vertices = elem.vertices(); let vertices = &elem.vertices;
let points: Vec<Point> = vertices.iter().map(|c| resolve(c.vertex())).collect(); let points: Vec<Point> = vertices.iter().map(|c| resolve(c.vertex())).collect();
let mut size = Size::zero(); let mut size = Size::zero();
@ -150,7 +150,7 @@ pub fn layout_curve(
) -> SourceResult<Frame> { ) -> SourceResult<Frame> {
let mut builder = CurveBuilder::new(region, styles); let mut builder = CurveBuilder::new(region, styles);
for item in elem.components() { for item in &elem.components {
match item { match item {
CurveComponent::Move(element) => { CurveComponent::Move(element) => {
let relative = element.relative(styles); let relative = element.relative(styles);
@ -399,7 +399,7 @@ pub fn layout_polygon(
region: Region, region: Region,
) -> SourceResult<Frame> { ) -> SourceResult<Frame> {
let points: Vec<Point> = elem let points: Vec<Point> = elem
.vertices() .vertices
.iter() .iter()
.map(|c| c.resolve(styles).zip_map(region.size, Rel::relative_to).to_point()) .map(|c| c.resolve(styles).zip_map(region.size, Rel::relative_to).to_point())
.collect(); .collect();

View File

@ -27,7 +27,7 @@ pub fn layout_stack(
let spacing = elem.spacing(styles); let spacing = elem.spacing(styles);
let mut deferred = None; let mut deferred = None;
for child in elem.children() { for child in &elem.children {
match child { match child {
StackChild::Spacing(kind) => { StackChild::Spacing(kind) => {
layouter.layout_spacing(*kind); layouter.layout_spacing(*kind);
@ -36,14 +36,14 @@ pub fn layout_stack(
StackChild::Block(block) => { StackChild::Block(block) => {
// Transparently handle `h`. // Transparently handle `h`.
if let (Axis::X, Some(h)) = (axis, block.to_packed::<HElem>()) { if let (Axis::X, Some(h)) = (axis, block.to_packed::<HElem>()) {
layouter.layout_spacing(*h.amount()); layouter.layout_spacing(h.amount);
deferred = None; deferred = None;
continue; continue;
} }
// Transparently handle `v`. // Transparently handle `v`.
if let (Axis::Y, Some(v)) = (axis, block.to_packed::<VElem>()) { if let (Axis::Y, Some(v)) = (axis, block.to_packed::<VElem>()) {
layouter.layout_spacing(*v.amount()); layouter.layout_spacing(v.amount);
deferred = None; deferred = None;
continue; continue;
} }

View File

@ -52,7 +52,7 @@ pub fn layout_rotate(
region, region,
size, size,
styles, styles,
elem.body(), &elem.body,
Transform::rotate(angle), Transform::rotate(angle),
align, align,
elem.reflow(styles), elem.reflow(styles),
@ -81,7 +81,7 @@ pub fn layout_scale(
region, region,
size, size,
styles, styles,
elem.body(), &elem.body,
Transform::scale(scale.x, scale.y), Transform::scale(scale.x, scale.y),
elem.origin(styles).resolve(styles), elem.origin(styles).resolve(styles),
elem.reflow(styles), elem.reflow(styles),
@ -169,7 +169,7 @@ pub fn layout_skew(
region, region,
size, size,
styles, styles,
elem.body(), &elem.body,
Transform::skew(ax, ay), Transform::skew(ax, ay),
align, align,
elem.reflow(styles), elem.reflow(styles),

View File

@ -800,7 +800,7 @@ impl ManualPageCounter {
let Some(elem) = elem.to_packed::<CounterUpdateElem>() else { let Some(elem) = elem.to_packed::<CounterUpdateElem>() else {
continue; continue;
}; };
if *elem.key() == CounterKey::Page { if elem.key == CounterKey::Page {
let mut state = CounterState(smallvec![self.logical]); let mut state = CounterState(smallvec![self.logical]);
state.update(engine, elem.update.clone())?; state.update(engine, elem.update.clone())?;
self.logical = state.first(); self.logical = state.first();

View File

@ -245,7 +245,7 @@ impl State {
for elem in introspector.query(&self.selector()) { for elem in introspector.query(&self.selector()) {
let elem = elem.to_packed::<StateUpdateElem>().unwrap(); let elem = elem.to_packed::<StateUpdateElem>().unwrap();
match elem.update() { match &elem.update {
StateUpdate::Set(value) => state = value.clone(), StateUpdate::Set(value) => state = value.clone(),
StateUpdate::Func(func) => { StateUpdate::Func(func) => {
state = func.call(&mut engine, Context::none().track(), [state])? state = func.call(&mut engine, Context::none().track(), [state])?

View File

@ -100,7 +100,7 @@ pub struct AlignElem {
impl Show for Packed<AlignElem> { impl Show for Packed<AlignElem> {
#[typst_macros::time(name = "align", span = self.span())] #[typst_macros::time(name = "align", span = self.span())]
fn show(&self, _: &mut Engine, styles: StyleChain) -> SourceResult<Content> { fn show(&self, _: &mut Engine, styles: StyleChain) -> SourceResult<Content> {
Ok(self.body().clone().aligned(self.alignment(styles))) Ok(self.body.clone().aligned(self.alignment(styles)))
} }
} }

View File

@ -166,7 +166,7 @@ impl Packed<InlineElem> {
styles: StyleChain, styles: StyleChain,
region: Size, region: Size,
) -> SourceResult<Vec<InlineItem>> { ) -> SourceResult<Vec<InlineItem>> {
self.body().call(engine, locator, styles, region) self.body.call(engine, locator, styles, region)
} }
} }

View File

@ -749,7 +749,7 @@ cast! {
impl Show for Packed<GridCell> { impl Show for Packed<GridCell> {
fn show(&self, _engine: &mut Engine, styles: StyleChain) -> SourceResult<Content> { 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))
} }
} }

View File

@ -42,16 +42,16 @@ pub fn grid_to_cellgrid<'a>(
// Use trace to link back to the grid when a specific cell errors // Use trace to link back to the grid when a specific cell errors
let tracepoint = || Tracepoint::Call(Some(eco_format!("grid"))); let tracepoint = || Tracepoint::Call(Some(eco_format!("grid")));
let resolve_item = |item: &GridItem| grid_item_to_resolvable(item, styles); let resolve_item = |item: &GridItem| grid_item_to_resolvable(item, styles);
let children = elem.children().iter().map(|child| match child { let children = elem.children.iter().map(|child| match child {
GridChild::Header(header) => ResolvableGridChild::Header { GridChild::Header(header) => ResolvableGridChild::Header {
repeat: header.repeat(styles), repeat: header.repeat(styles),
span: header.span(), span: header.span(),
items: header.children().iter().map(resolve_item), items: header.children.iter().map(resolve_item),
}, },
GridChild::Footer(footer) => ResolvableGridChild::Footer { GridChild::Footer(footer) => ResolvableGridChild::Footer {
repeat: footer.repeat(styles), repeat: footer.repeat(styles),
span: footer.span(), span: footer.span(),
items: footer.children().iter().map(resolve_item), items: footer.children.iter().map(resolve_item),
}, },
GridChild::Item(item) => { GridChild::Item(item) => {
ResolvableGridChild::Item(grid_item_to_resolvable(item, styles)) ResolvableGridChild::Item(grid_item_to_resolvable(item, styles))
@ -95,16 +95,16 @@ pub fn table_to_cellgrid<'a>(
// Use trace to link back to the table when a specific cell errors // Use trace to link back to the table when a specific cell errors
let tracepoint = || Tracepoint::Call(Some(eco_format!("table"))); let tracepoint = || Tracepoint::Call(Some(eco_format!("table")));
let resolve_item = |item: &TableItem| table_item_to_resolvable(item, styles); let resolve_item = |item: &TableItem| table_item_to_resolvable(item, styles);
let children = elem.children().iter().map(|child| match child { let children = elem.children.iter().map(|child| match child {
TableChild::Header(header) => ResolvableGridChild::Header { TableChild::Header(header) => ResolvableGridChild::Header {
repeat: header.repeat(styles), repeat: header.repeat(styles),
span: header.span(), span: header.span(),
items: header.children().iter().map(resolve_item), items: header.children.iter().map(resolve_item),
}, },
TableChild::Footer(footer) => ResolvableGridChild::Footer { TableChild::Footer(footer) => ResolvableGridChild::Footer {
repeat: footer.repeat(styles), repeat: footer.repeat(styles),
span: footer.span(), span: footer.span(),
items: footer.children().iter().map(resolve_item), items: footer.children.iter().map(resolve_item),
}, },
TableChild::Item(item) => { TableChild::Item(item) => {
ResolvableGridChild::Item(table_item_to_resolvable(item, styles)) ResolvableGridChild::Item(table_item_to_resolvable(item, styles))

View File

@ -29,6 +29,6 @@ pub struct HideElem {
impl Show for Packed<HideElem> { impl Show for Packed<HideElem> {
#[typst_macros::time(name = "hide", span = self.span())] #[typst_macros::time(name = "hide", span = self.span())]
fn show(&self, _: &mut Engine, _: StyleChain) -> SourceResult<Content> { fn show(&self, _: &mut Engine, _: StyleChain) -> SourceResult<Content> {
Ok(self.body().clone().styled(HideElem::set_hidden(true))) Ok(self.body.clone().styled(HideElem::set_hidden(true)))
} }
} }

View File

@ -89,7 +89,7 @@ impl Show for Packed<LayoutElem> {
let loc = elem.location().unwrap(); let loc = elem.location().unwrap();
let context = Context::new(Some(loc), Some(styles)); let context = Context::new(Some(loc), Some(styles));
let result = elem let result = elem
.func() .func
.call( .call(
engine, engine,
context.track(), context.track(),

View File

@ -143,7 +143,7 @@ cast! {
self => self.0.into_value(), self => self.0.into_value(),
v: char => Self::new(v), v: char => Self::new(v),
v: Content => match v.to_packed::<TextElem>() { v: Content => match v.to_packed::<TextElem>() {
Some(elem) => Value::Str(elem.text().clone().into()).cast()?, Some(elem) => Value::Str(elem.text.clone().into()).cast()?,
None => bail!("expected text"), None => bail!("expected text"),
}, },
} }

View File

@ -47,9 +47,9 @@ impl Packed<AttachElem> {
/// base AttachElem where possible. /// base AttachElem where possible.
pub fn merge_base(&self) -> Option<Self> { pub fn merge_base(&self) -> Option<Self> {
// Extract from an EquationElem. // Extract from an EquationElem.
let mut base = self.base(); let mut base = &self.base;
while let Some(equation) = base.to_packed::<EquationElem>() { while let Some(equation) = base.to_packed::<EquationElem>() {
base = equation.body(); base = &equation.body;
} }
// Move attachments from elem into base where possible. // Move attachments from elem into base where possible.

View File

@ -638,7 +638,7 @@ impl<'a> Generator<'a> {
for elem in &self.groups { for elem in &self.groups {
let group = elem.to_packed::<CiteGroup>().unwrap(); let group = elem.to_packed::<CiteGroup>().unwrap();
let location = elem.location().unwrap(); let location = elem.location().unwrap();
let children = group.children(); let children = &group.children;
// Groups should never be empty. // Groups should never be empty.
let Some(first) = children.first() else { continue }; 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. // Create infos and items for each child in the group.
for child in children { for child in children {
let key = *child.key(); let Some(entry) = database.get(child.key) else {
let Some(entry) = database.get(key) else {
errors.push(error!( errors.push(error!(
child.span(), child.span(),
"key `{}` does not exist in the bibliography", "key `{}` does not exist in the bibliography",
key.resolve() child.key.resolve()
)); ));
continue; continue;
}; };
@ -682,7 +681,7 @@ impl<'a> Generator<'a> {
}; };
normal &= special_form.is_none(); 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)); items.push(CitationItem::new(entry, locator, None, hidden, special_form));
} }

View File

@ -257,7 +257,7 @@ impl Synthesize for Packed<FigureElem> {
// Determine the figure's kind. // Determine the figure's kind.
let kind = elem.kind(styles).unwrap_or_else(|| { let kind = elem.kind(styles).unwrap_or_else(|| {
elem.body() elem.body
.query_first(&Selector::can::<dyn Figurable>()) .query_first(&Selector::can::<dyn Figurable>())
.map(|elem| FigureKind::Elem(elem.func())) .map(|elem| FigureKind::Elem(elem.func()))
.unwrap_or_else(|| FigureKind::Elem(ImageElem::elem())) .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 // Resolve the supplement with the first descendant of the kind or
// just the body, if none was found. // just the body, if none was found.
let descendant = match kind { let descendant = match kind {
FigureKind::Elem(func) => elem FigureKind::Elem(func) => {
.body() elem.body.query_first(&Selector::Elem(func, None)).map(Cow::Owned)
.query_first(&Selector::Elem(func, None)) }
.map(Cow::Owned),
FigureKind::Name(_) => None, 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])?) Some(supplement.resolve(engine, styles, [target])?)
} }
}; };
@ -437,7 +436,7 @@ impl Outlinable for Packed<FigureElem> {
return Ok(None); return Ok(None);
}; };
let mut realized = caption.body().clone(); let mut realized = caption.body.clone();
if let ( if let (
Smart::Custom(Some(Supplement::Content(mut supplement))), Smart::Custom(Some(Supplement::Content(mut supplement))),
Some(Some(counter)), Some(Some(counter)),
@ -460,7 +459,7 @@ impl Outlinable for Packed<FigureElem> {
let separator = caption.get_separator(StyleChain::default()); let separator = caption.get_separator(StyleChain::default());
realized = supplement + numbers + separator + caption.body(); realized = supplement + numbers + separator + caption.body.clone();
} }
Ok(Some(realized)) Ok(Some(realized))
@ -604,7 +603,7 @@ impl Synthesize for Packed<FigureCaption> {
impl Show for Packed<FigureCaption> { impl Show for Packed<FigureCaption> {
#[typst_macros::time(name = "figure.caption", span = self.span())] #[typst_macros::time(name = "figure.caption", span = self.span())]
fn show(&self, engine: &mut Engine, styles: StyleChain) -> SourceResult<Content> { fn show(&self, engine: &mut Engine, styles: StyleChain) -> SourceResult<Content> {
let mut realized = self.body().clone(); let mut realized = self.body.clone();
if let ( if let (
Some(Some(mut supplement)), Some(Some(mut supplement)),

View File

@ -105,12 +105,12 @@ impl FootnoteElem {
/// Tests if this footnote is a reference to another footnote. /// Tests if this footnote is a reference to another footnote.
pub fn is_ref(&self) -> bool { 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. /// Returns the content of the body of this footnote if it is not a ref.
pub fn body_content(&self) -> Option<&Content> { pub fn body_content(&self) -> Option<&Content> {
match self.body() { match &self.body {
FootnoteBody::Content(content) => Some(content), FootnoteBody::Content(content) => Some(content),
_ => None, _ => None,
} }
@ -120,9 +120,9 @@ impl FootnoteElem {
impl Packed<FootnoteElem> { impl Packed<FootnoteElem> {
/// Returns the location of the definition of this footnote. /// Returns the location of the definition of this footnote.
pub fn declaration_location(&self, engine: &Engine) -> StrResult<Location> { pub fn declaration_location(&self, engine: &Engine) -> StrResult<Location> {
match self.body() { match self.body {
FootnoteBody::Reference(label) => { FootnoteBody::Reference(label) => {
let element = engine.introspector.query_label(*label)?; let element = engine.introspector.query_label(label)?;
let footnote = element let footnote = element
.to_packed::<FootnoteElem>() .to_packed::<FootnoteElem>()
.ok_or("referenced element should be a footnote")?; .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())] #[typst_macros::time(name = "footnote.entry", span = self.span())]
fn show(&self, engine: &mut Engine, styles: StyleChain) -> SourceResult<Content> { fn show(&self, engine: &mut Engine, styles: StyleChain) -> SourceResult<Content> {
let span = self.span(); let span = self.span();
let note = self.note();
let number_gap = Em::new(0.05); let number_gap = Em::new(0.05);
let default = StyleChain::default(); let default = StyleChain::default();
let numbering = note.numbering(default); let numbering = self.note.numbering(default);
let counter = Counter::of(FootnoteElem::elem()); let counter = Counter::of(FootnoteElem::elem());
let Some(loc) = note.location() else { let Some(loc) = self.note.location() else {
bail!( bail!(
span, "footnote entry must have a location"; span, "footnote entry must have a location";
hint: "try using a query or a show rule to customize the footnote instead" 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(), HElem::new(self.indent(styles).into()).pack(),
sup, sup,
HElem::new(number_gap.into()).with_weak(true).pack(), HElem::new(number_gap.into()).with_weak(true).pack(),
note.body_content().unwrap().clone(), self.note.body_content().unwrap().clone(),
])) ]))
} }
} }

View File

@ -223,7 +223,7 @@ impl Show for Packed<HeadingElem> {
const SPACING_TO_NUMBERING: Em = Em::new(0.3); const SPACING_TO_NUMBERING: Em = Em::new(0.3);
let span = self.span(); let span = self.span();
let mut realized = self.body().clone(); let mut realized = self.body.clone();
let hanging_indent = self.hanging_indent(styles); let hanging_indent = self.hanging_indent(styles);
let mut indent = match hanging_indent { let mut indent = match hanging_indent {
@ -360,7 +360,7 @@ impl Outlinable for Packed<HeadingElem> {
return Ok(None); 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() { if let Some(numbering) = (**self).numbering(StyleChain::default()).as_ref() {
let numbers = Counter::of(HeadingElem::elem()).display_at_loc( let numbers = Counter::of(HeadingElem::elem()).display_at_loc(
engine, engine,

View File

@ -102,11 +102,10 @@ impl LinkElem {
impl Show for Packed<LinkElem> { impl Show for Packed<LinkElem> {
#[typst_macros::time(name = "link", span = self.span())] #[typst_macros::time(name = "link", span = self.span())]
fn show(&self, engine: &mut Engine, styles: StyleChain) -> SourceResult<Content> { fn show(&self, engine: &mut Engine, styles: StyleChain) -> SourceResult<Content> {
let body = self.body().clone(); let body = self.body.clone();
let dest = self.dest();
Ok(if TargetElem::target_in(styles).is_html() { 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) HtmlElem::new(tag::a)
.with_attr(attr::href, url.clone().into_inner()) .with_attr(attr::href, url.clone().into_inner())
.with_body(Some(body)) .with_body(Some(body))
@ -120,7 +119,7 @@ impl Show for Packed<LinkElem> {
body body
} }
} else { } else {
let linked = match self.dest() { let linked = match &self.dest {
LinkTarget::Dest(dest) => body.linked(dest.clone()), LinkTarget::Dest(dest) => body.linked(dest.clone()),
LinkTarget::Label(label) => { LinkTarget::Label(label) => {
let elem = engine.introspector.query_label(*label).at(self.span())?; let elem = engine.introspector.query_label(*label).at(self.span())?;

View File

@ -219,8 +219,7 @@ impl Show for Packed<OutlineElem> {
continue; continue;
}; };
let level = entry.level(); if depth < entry.level {
if depth < *level {
continue; continue;
} }
@ -229,7 +228,7 @@ impl Show for Packed<OutlineElem> {
while ancestors while ancestors
.last() .last()
.and_then(|ancestor| ancestor.with::<dyn Outlinable>()) .and_then(|ancestor| ancestor.with::<dyn Outlinable>())
.is_some_and(|last| last.level() >= *level) .is_some_and(|last| last.level() >= entry.level)
{ {
ancestors.pop(); ancestors.pop();
} }
@ -483,7 +482,7 @@ impl Show for Packed<OutlineEntry> {
#[typst_macros::time(name = "outline.entry", span = self.span())] #[typst_macros::time(name = "outline.entry", span = self.span())]
fn show(&self, _: &mut Engine, styles: StyleChain) -> SourceResult<Content> { fn show(&self, _: &mut Engine, styles: StyleChain) -> SourceResult<Content> {
let mut seq = vec![]; let mut seq = vec![];
let elem = self.element(); let elem = &self.element;
// In case a user constructs an outline entry with an arbitrary element. // In case a user constructs an outline entry with an arbitrary element.
let Some(location) = elem.location() else { let Some(location) = elem.location() else {
@ -512,7 +511,7 @@ impl Show for Packed<OutlineEntry> {
seq.push(TextElem::packed("\u{202B}")); 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 { if rtl {
// "Pop Directional Formatting" // "Pop Directional Formatting"
@ -520,7 +519,7 @@ impl Show for Packed<OutlineEntry> {
} }
// Add filler symbols between the section name and page number. // 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(SpaceElem::shared().clone());
seq.push( seq.push(
BoxElem::new() BoxElem::new()
@ -535,7 +534,7 @@ impl Show for Packed<OutlineEntry> {
} }
// Add the page number. // 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); seq.push(page);
Ok(Content::sequence(seq)) Ok(Content::sequence(seq))

View File

@ -156,7 +156,7 @@ cast! {
impl Show for Packed<QuoteElem> { impl Show for Packed<QuoteElem> {
#[typst_macros::time(name = "quote", span = self.span())] #[typst_macros::time(name = "quote", span = self.span())]
fn show(&self, _: &mut Engine, styles: StyleChain) -> SourceResult<Content> { 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); let block = self.block(styles);
if self.quotes(styles) == Smart::Custom(true) || !block { if self.quotes(styles) == Smart::Custom(true) || !block {

View File

@ -182,9 +182,8 @@ impl Synthesize for Packed<RefElem> {
elem.push_citation(Some(citation)); elem.push_citation(Some(citation));
elem.push_element(None); elem.push_element(None);
let target = *elem.target(); if !BibliographyElem::has(engine, elem.target) {
if !BibliographyElem::has(engine, target) { if let Ok(found) = engine.introspector.query_label(elem.target).cloned() {
if let Ok(found) = engine.introspector.query_label(target).cloned() {
elem.push_element(Some(found)); elem.push_element(Some(found));
return Ok(()); return Ok(());
} }
@ -197,8 +196,7 @@ impl Synthesize for Packed<RefElem> {
impl Show for Packed<RefElem> { impl Show for Packed<RefElem> {
#[typst_macros::time(name = "ref", span = self.span())] #[typst_macros::time(name = "ref", span = self.span())]
fn show(&self, engine: &mut Engine, styles: StyleChain) -> SourceResult<Content> { fn show(&self, engine: &mut Engine, styles: StyleChain) -> SourceResult<Content> {
let target = *self.target(); let elem = engine.introspector.query_label(self.target);
let elem = engine.introspector.query_label(target);
let span = self.span(); let span = self.span();
let form = self.form(styles); let form = self.form(styles);
@ -229,7 +227,7 @@ impl Show for Packed<RefElem> {
} }
// RefForm::Normal // RefForm::Normal
if BibliographyElem::has(engine, target) { if BibliographyElem::has(engine, self.target) {
if elem.is_ok() { if elem.is_ok() {
bail!(span, "label occurs in the document and its bibliography"); bail!(span, "label occurs in the document and its bibliography");
} }
@ -240,7 +238,7 @@ impl Show for Packed<RefElem> {
let elem = elem.at(span)?; let elem = elem.at(span)?;
if let Some(footnote) = elem.to_packed::<FootnoteElem>() { 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(); let elem = elem.clone();
@ -319,7 +317,7 @@ fn to_citation(
engine: &mut Engine, engine: &mut Engine,
styles: StyleChain, styles: StyleChain,
) -> SourceResult<Packed<CiteElem>> { ) -> 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() { match reference.supplement(styles).clone() {
Smart::Custom(Some(Supplement::Content(content))) => Some(content), Smart::Custom(Some(Supplement::Content(content))) => Some(content),
_ => None, _ => None,

View File

@ -706,7 +706,7 @@ cast! {
impl Show for Packed<TableCell> { impl Show for Packed<TableCell> {
fn show(&self, _engine: &mut Engine, styles: StyleChain) -> SourceResult<Content> { 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))
} }
} }

View File

@ -151,12 +151,12 @@ impl Show for Packed<TermsElem> {
.then(|| HElem::new((-hanging_indent).into()).pack().spanned(span)); .then(|| HElem::new((-hanging_indent).into()).pack().spanned(span));
let mut children = vec![]; let mut children = vec![];
for child in self.children().iter() { for child in self.children.iter() {
let mut seq = vec![]; let mut seq = vec![];
seq.extend(unpad.clone()); seq.extend(unpad.clone());
seq.push(child.term().clone().strong()); seq.push(child.term.clone().strong());
seq.push((*separator).clone()); seq.push((*separator).clone());
seq.push(child.description().clone()); seq.push(child.description.clone());
children.push(StackChild::Block(Content::sequence(seq))); children.push(StackChild::Block(Content::sequence(seq)));
} }

View File

@ -81,7 +81,7 @@ pub struct UnderlineElem {
impl Show for Packed<UnderlineElem> { impl Show for Packed<UnderlineElem> {
#[typst_macros::time(name = "underline", span = self.span())] #[typst_macros::time(name = "underline", span = self.span())]
fn show(&self, _: &mut Engine, styles: StyleChain) -> SourceResult<Content> { fn show(&self, _: &mut Engine, styles: StyleChain) -> SourceResult<Content> {
Ok(self.body().clone().styled(TextElem::set_deco(smallvec![Decoration { Ok(self.body.clone().styled(TextElem::set_deco(smallvec![Decoration {
line: DecoLine::Underline { line: DecoLine::Underline {
stroke: self.stroke(styles).unwrap_or_default(), stroke: self.stroke(styles).unwrap_or_default(),
offset: self.offset(styles), offset: self.offset(styles),
@ -173,7 +173,7 @@ pub struct OverlineElem {
impl Show for Packed<OverlineElem> { impl Show for Packed<OverlineElem> {
#[typst_macros::time(name = "overline", span = self.span())] #[typst_macros::time(name = "overline", span = self.span())]
fn show(&self, _: &mut Engine, styles: StyleChain) -> SourceResult<Content> { fn show(&self, _: &mut Engine, styles: StyleChain) -> SourceResult<Content> {
Ok(self.body().clone().styled(TextElem::set_deco(smallvec![Decoration { Ok(self.body.clone().styled(TextElem::set_deco(smallvec![Decoration {
line: DecoLine::Overline { line: DecoLine::Overline {
stroke: self.stroke(styles).unwrap_or_default(), stroke: self.stroke(styles).unwrap_or_default(),
offset: self.offset(styles), offset: self.offset(styles),
@ -250,7 +250,7 @@ pub struct StrikeElem {
impl Show for Packed<StrikeElem> { impl Show for Packed<StrikeElem> {
#[typst_macros::time(name = "strike", span = self.span())] #[typst_macros::time(name = "strike", span = self.span())]
fn show(&self, _: &mut Engine, styles: StyleChain) -> SourceResult<Content> { fn show(&self, _: &mut Engine, styles: StyleChain) -> SourceResult<Content> {
Ok(self.body().clone().styled(TextElem::set_deco(smallvec![Decoration { Ok(self.body.clone().styled(TextElem::set_deco(smallvec![Decoration {
// Note that we do not support evade option for strikethrough. // Note that we do not support evade option for strikethrough.
line: DecoLine::Strikethrough { line: DecoLine::Strikethrough {
stroke: self.stroke(styles).unwrap_or_default(), stroke: self.stroke(styles).unwrap_or_default(),
@ -345,7 +345,7 @@ pub struct HighlightElem {
impl Show for Packed<HighlightElem> { impl Show for Packed<HighlightElem> {
#[typst_macros::time(name = "highlight", span = self.span())] #[typst_macros::time(name = "highlight", span = self.span())]
fn show(&self, _: &mut Engine, styles: StyleChain) -> SourceResult<Content> { fn show(&self, _: &mut Engine, styles: StyleChain) -> SourceResult<Content> {
Ok(self.body().clone().styled(TextElem::set_deco(smallvec![Decoration { Ok(self.body.clone().styled(TextElem::set_deco(smallvec![Decoration {
line: DecoLine::Highlight { line: DecoLine::Highlight {
fill: self.fill(styles), fill: self.fill(styles),
stroke: self stroke: self

View File

@ -794,7 +794,7 @@ impl Construct for TextElem {
impl PlainText for Packed<TextElem> { impl PlainText for Packed<TextElem> {
fn plain_text(&self, text: &mut EcoString) { fn plain_text(&self, text: &mut EcoString) {
text.push_str(self.text()); text.push_str(&self.text);
} }
} }

View File

@ -315,7 +315,7 @@ impl Packed<RawElem> {
#[comemo::memoize] #[comemo::memoize]
fn highlight(&self, styles: StyleChain) -> Vec<Packed<RawLine>> { fn highlight(&self, styles: StyleChain) -> Vec<Packed<RawLine>> {
let elem = self.as_ref(); let elem = self.as_ref();
let lines = preprocess(elem.text(), styles, self.span()); let lines = preprocess(&elem.text, styles, self.span());
let count = lines.len() as i64; let count = lines.len() as i64;
let lang = elem let lang = elem
@ -490,7 +490,7 @@ impl Figurable for Packed<RawElem> {}
impl PlainText for Packed<RawElem> { impl PlainText for Packed<RawElem> {
fn plain_text(&self, text: &mut EcoString) { fn plain_text(&self, text: &mut EcoString) {
text.push_str(&self.text().get()); text.push_str(&self.text.get());
} }
} }
@ -638,13 +638,13 @@ pub struct RawLine {
impl Show for Packed<RawLine> { impl Show for Packed<RawLine> {
#[typst_macros::time(name = "raw.line", span = self.span())] #[typst_macros::time(name = "raw.line", span = self.span())]
fn show(&self, _: &mut Engine, _styles: StyleChain) -> SourceResult<Content> { fn show(&self, _: &mut Engine, _styles: StyleChain) -> SourceResult<Content> {
Ok(self.body().clone()) Ok(self.body.clone())
} }
} }
impl PlainText for Packed<RawLine> { impl PlainText for Packed<RawLine> {
fn plain_text(&self, text: &mut EcoString) { fn plain_text(&self, text: &mut EcoString) {
text.push_str(self.text()); text.push_str(&self.text);
} }
} }

View File

@ -50,7 +50,7 @@ pub struct SubElem {
impl Show for Packed<SubElem> { impl Show for Packed<SubElem> {
#[typst_macros::time(name = "sub", span = self.span())] #[typst_macros::time(name = "sub", span = self.span())]
fn show(&self, engine: &mut Engine, styles: StyleChain) -> SourceResult<Content> { fn show(&self, engine: &mut Engine, styles: StyleChain) -> SourceResult<Content> {
let body = self.body().clone(); let body = self.body.clone();
if self.typographic(styles) { if self.typographic(styles) {
if let Some(text) = convert_script(&body, true) { if let Some(text) = convert_script(&body, true) {
@ -109,7 +109,7 @@ pub struct SuperElem {
impl Show for Packed<SuperElem> { impl Show for Packed<SuperElem> {
#[typst_macros::time(name = "super", span = self.span())] #[typst_macros::time(name = "super", span = self.span())]
fn show(&self, engine: &mut Engine, styles: StyleChain) -> SourceResult<Content> { fn show(&self, engine: &mut Engine, styles: StyleChain) -> SourceResult<Content> {
let body = self.body().clone(); let body = self.body.clone();
if self.typographic(styles) { if self.typographic(styles) {
if let Some(text) = convert_script(&body, false) { if let Some(text) = convert_script(&body, false) {
@ -132,9 +132,9 @@ fn convert_script(content: &Content, sub: bool) -> Option<EcoString> {
Some(' '.into()) Some(' '.into())
} else if let Some(elem) = content.to_packed::<TextElem>() { } else if let Some(elem) = content.to_packed::<TextElem>() {
if sub { if sub {
elem.text().chars().map(to_subscript_codepoint).collect() elem.text.chars().map(to_subscript_codepoint).collect()
} else { } else {
elem.text().chars().map(to_superscript_codepoint).collect() elem.text.chars().map(to_superscript_codepoint).collect()
} }
} else if let Some(sequence) = content.to_packed::<SequenceElem>() { } else if let Some(sequence) = content.to_packed::<SequenceElem>() {
sequence sequence

View File

@ -53,6 +53,6 @@ pub struct SmallcapsElem {
impl Show for Packed<SmallcapsElem> { impl Show for Packed<SmallcapsElem> {
#[typst_macros::time(name = "smallcaps", span = self.span())] #[typst_macros::time(name = "smallcaps", span = self.span())]
fn show(&self, _: &mut Engine, _: StyleChain) -> SourceResult<Content> { fn show(&self, _: &mut Engine, _: StyleChain) -> SourceResult<Content> {
Ok(self.body().clone().styled(TextElem::set_smallcaps(true))) Ok(self.body.clone().styled(TextElem::set_smallcaps(true)))
} }
} }

View File

@ -63,6 +63,11 @@ impl Elem {
self.real_fields().filter(|field| !field.ghost) self.real_fields().filter(|field| !field.ghost)
} }
/// Fields that get accessor, with, and push methods.
fn accessor_fields(&self) -> impl Iterator<Item = &Field> + Clone {
self.struct_fields().filter(|field| !field.required)
}
/// Fields that are relevant for equality. /// Fields that are relevant for equality.
/// ///
/// Synthesized fields are excluded to ensure equality before and after /// Synthesized fields are excluded to ensure equality before and after
@ -442,9 +447,9 @@ fn create_inherent_impl(element: &Elem) -> TokenStream {
let Elem { ident, .. } = element; let Elem { ident, .. } = element;
let new_func = create_new_func(element); let new_func = create_new_func(element);
let with_field_methods = element.struct_fields().map(create_with_field_method); let with_field_methods = element.accessor_fields().map(create_with_field_method);
let push_field_methods = element.struct_fields().map(create_push_field_method); let push_field_methods = element.accessor_fields().map(create_push_field_method);
let field_methods = element.struct_fields().map(create_field_method); let field_methods = element.accessor_fields().map(create_field_method);
let field_in_methods = element.style_fields().map(create_field_in_method); let field_in_methods = element.style_fields().map(create_field_in_method);
let set_field_methods = element.style_fields().map(create_set_field_method); let set_field_methods = element.style_fields().map(create_set_field_method);

View File

@ -59,7 +59,7 @@ fn embed_file(
let embedded_file_stream_ref = chunk.alloc.bump(); let embedded_file_stream_ref = chunk.alloc.bump();
let file_spec_dict_ref = chunk.alloc.bump(); let file_spec_dict_ref = chunk.alloc.bump();
let data = embed.data().as_slice(); let data = embed.data.as_slice();
let compressed = deflate(data); let compressed = deflate(data);
let mut embedded_file = chunk.embedded_file(embedded_file_stream_ref, &compressed); let mut embedded_file = chunk.embedded_file(embedded_file_stream_ref, &compressed);

View File

@ -184,8 +184,7 @@ fn write_outline_item(
outline.count(-(node.children.len() as i32)); outline.count(-(node.children.len() as i32));
} }
let body = node.element.body(); outline.title(TextStr::trimmed(node.element.body.plain_text().trim()));
outline.title(TextStr::trimmed(body.plain_text().trim()));
let loc = node.element.location().unwrap(); let loc = node.element.location().unwrap();
let pos = ctx.document.introspector.position(loc); let pos = ctx.document.introspector.position(loc);