Skip to main content

Fragment

Struct Fragment 

Source
pub struct Fragment {
    pub root: NodeId,
    pub nodes: Vec<LayoutNode>,
    pub source_map: SourceMap,
    pub metadata: FragmentMetadata,
    pub surface: Surface,
}
Expand description

One typeset fragment: a tree of layout nodes rooted at root, stored densely by id.

Fields§

§root: NodeId

The root node, placed at (0, 0) with its reference point on the surface baseline.

§nodes: Vec<LayoutNode>

Every node of the tree, nodes[i].id == NodeId(i).

§source_map: SourceMap

Source files and enclosing construct spans.

§metadata: FragmentMetadata

How the fragment was produced.

§surface: Surface

Extent of the root box, surface.baseline == root.height.

Implementations§

Source§

impl Fragment

Source

pub fn new( root: NodeId, nodes: Vec<LayoutNode>, source_map: SourceMap, metadata: FragmentMetadata, ) -> Result<Self, FragmentError>

Builds a fragment, deriving the surface from the root and checking every invariant.

Source

pub fn validate(&self) -> Result<(), FragmentError>

Checks dense ids, a single tree under the root, the root placement, the surface and source ids.

Source

pub fn node(&self, id: NodeId) -> Option<&LayoutNode>

Returns the node with the given id in constant time.

Source

pub fn root_node(&self) -> Option<&LayoutNode>

Returns the root node, None for an empty fragment.

Source

pub fn children(&self, id: NodeId) -> &[NodeId]

Returns the children of a node, empty for leaves and unknown ids.

Source

pub fn source_entries_for_node( &self, node: NodeId, ) -> impl Iterator<Item = &SourceMapEntry>

Iterates the enclosing construct entries of a node, innermost first.

Source

pub fn source_origins_for_node( &self, node: NodeId, ) -> impl Iterator<Item = SourceOrigin<'_>>

Iterates the node’s primary origin followed by its enclosing construct origins.

Source

pub fn primary_source_for_node(&self, node: NodeId) -> Option<SourceRange>

Returns the primary source range of a node.

Source

pub fn glyph_source_range( &self, node: NodeId, glyph_index: usize, ) -> Option<SourceRange>

Resolves a glyph’s cluster span to a range in the node’s primary source file.

Source

pub fn glyph_source_origin( &self, node: NodeId, glyph_index: usize, ) -> Option<SourceOrigin<'_>>

Resolves a glyph’s cluster span to a full source origin.

Source

pub fn flatten(&self) -> Vec<Placed<'_>>

Absolute glyphs and rules in tree order, y down, origin at the surface top left.

Trait Implementations§

Source§

impl Clone for Fragment

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Fragment

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Fragment

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl PartialEq for Fragment

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Fragment

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.