Skip to main content

ProvenanceBuilder

Struct ProvenanceBuilder 

Source
pub struct ProvenanceBuilder { /* private fields */ }
Expand description

Builds a SourceInfo by tiling a decoded string’s content against the source bytes it came from.

Construct with ProvenanceBuilder::in_file or ProvenanceBuilder::in_parent, describe the decode with verbatim and replacement calls in content order, then call finish.

Implementations§

Source§

impl ProvenanceBuilder

Source

pub fn in_file(file_id: FileId, anchor: usize) -> Self

Start a builder whose pieces are Original ranges directly in file_id.

anchor is the scalar’s span start; finish() uses it when the piece list ends up empty, since an empty piece list has no source range to infer a position from.

Source

pub fn in_parent(parent: SourceInfo, anchor: usize) -> Self

Start a builder whose pieces are Substring ranges over parent.

parent may itself be a Concat (e.g. q2’s cell-options path hands quarto_yaml::parse_with_parent a SourceInfo::concat(..)). The builder never resolves absolute positions out of parent — see finish — so this is safe regardless of what shape parent is.

anchor is the scalar’s span start, in parent’s coordinate space; see in_file for why it is needed.

Source

pub fn verbatim(&mut self, src_range: Range<usize>)

Record src_range.len() source bytes decoding to that many content bytes, unchanged.

This is a caller assertion: the builder takes byte-identity on trust and never re-derives it from lengths. Adjacent verbatim calls whose source ranges abut are merged; a replacement never coalesces with anything, however convenient its length.

Source

pub fn replacement(&mut self, src_range: Range<usize>, out_len: usize)

Record src_range.len() source bytes decoding to out_len content bytes, where source and content are not asserted to be byte-identical.

out_len == 0 is a deletion. An empty src_range with out_len > 0 is synthesis: content with no corresponding source byte (e.g. a chomped block scalar’s trailing newline at EOF).

Source

pub fn finish(self) -> SourceInfo

Emit the tiled SourceInfo: Original/Substring if the piece list collapsed to exactly one verbatim piece (or is empty), a Concat otherwise.

This never calls resolve_byte_range — on the parent or on anything derived from it — because in_parent’s parent may be a Concat, for which that accessor returns None. Positions are always built from the piece’s own src_range, never resolved.

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> 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.