diff --git a/crates/typst-pdf/src/outline.rs b/crates/typst-pdf/src/outline.rs index 172f6d3cc..238938730 100644 --- a/crates/typst-pdf/src/outline.rs +++ b/crates/typst-pdf/src/outline.rs @@ -19,7 +19,7 @@ pub(crate) fn write_outline(ctx: &mut PdfContext) -> Option { let mut last_skipped_level = None; let elements = ctx.document.introspector.query(&HeadingElem::elem().select()); for elem in elements.iter() { - let heading = elem.to::().unwrap(); + let heading = elem.to_packed::().unwrap(); let leaf = HeadingNode::leaf(heading); if leaf.bookmarked { diff --git a/crates/typst/src/engine.rs b/crates/typst/src/engine.rs index 7f094578b..a5408d293 100644 --- a/crates/typst/src/engine.rs +++ b/crates/typst/src/engine.rs @@ -1,3 +1,5 @@ +//! Definition of the central compilation context. + use std::sync::atomic::{AtomicUsize, Ordering}; use comemo::{Track, Tracked, TrackedMut, Validate}; diff --git a/crates/typst/src/foundations/cast.rs b/crates/typst/src/foundations/cast.rs index 2f7e1dad4..9c25aa8e9 100644 --- a/crates/typst/src/foundations/cast.rs +++ b/crates/typst/src/foundations/cast.rs @@ -256,7 +256,7 @@ impl FromValue for Value { impl FromValue for Packed { fn from_value(mut value: Value) -> StrResult { if let Value::Content(content) = value { - match content.to_packed::() { + match content.into_packed::() { Ok(packed) => return Ok(packed), Err(content) => value = Value::Content(content), } diff --git a/crates/typst/src/foundations/content.rs b/crates/typst/src/foundations/content.rs index 3ba458afd..52198642b 100644 --- a/crates/typst/src/foundations/content.rs +++ b/crates/typst/src/foundations/content.rs @@ -240,20 +240,25 @@ impl Content { } /// Downcasts the element to a packed value. - pub fn to(&self) -> Option<&Packed> { + pub fn to_packed(&self) -> Option<&Packed> { Packed::from_ref(self) } /// Downcasts the element to a mutable packed value. - pub fn to_mut(&mut self) -> Option<&mut Packed> { + pub fn to_packed_mut(&mut self) -> Option<&mut Packed> { Packed::from_mut(self) } /// Downcasts the element into an owned packed value. - pub fn to_packed(self) -> Result, Self> { + pub fn into_packed(self) -> Result, Self> { Packed::from_owned(self) } + /// Extract the raw underlying element. + pub fn unpack(self) -> Result { + self.into_packed::().map(Packed::unpack) + } + /// Makes sure the content is not shared and returns a mutable reference to /// the inner data. fn make_mut(&mut self) -> &mut Inner { @@ -309,7 +314,7 @@ impl Content { /// Whether the content is an empty sequence. pub fn is_empty(&self) -> bool { - let Some(sequence) = self.to::() else { + let Some(sequence) = self.to_packed::() else { return false; }; @@ -323,7 +328,7 @@ impl Content { /// Access the children if this is a sequence. pub fn to_sequence(&self) -> Option>> { - let sequence = self.to::()?; + let sequence = self.to_packed::()?; Some(sequence.children.iter()) } @@ -338,7 +343,7 @@ impl Content { /// Access the child and styles. pub fn to_styled(&self) -> Option<(&Content, &Styles)> { - let styled = self.to::()?; + let styled = self.to_packed::()?; let child = styled.child(); let styles = styled.styles(); Some((child, styles)) @@ -364,7 +369,7 @@ impl Content { /// Style this content with a style entry. pub fn styled(mut self, style: impl Into