pub struct Source { /* private fields */ }Expand description
Original YAML input plus line-start metadata.
Implementations§
Source§impl Source
impl Source
Sourcepub fn new(text: String) -> Result<Source, YamlError>
pub fn new(text: String) -> Result<Source, YamlError>
Builds a source buffer, validates YAML 1.2.2 printable characters, and records all line starts.
§Errors
Returns an error when text contains characters that are not valid in a
YAML 1.2.2 stream.
Sourcepub fn line_starts(&self) -> &[u32]
pub fn line_starts(&self) -> &[u32]
Returns the recorded line-start byte offsets.
Sourcepub fn slice(&self, span: Span) -> &str
pub fn slice(&self, span: Span) -> &str
Returns the source slice for span.
§Panics
Panics if span is outside the source or does not fall on UTF-8
boundaries. Use Source::try_slice when handling user-provided spans.
Sourcepub fn try_slice(&self, span: Span) -> Result<&str, YamlError>
pub fn try_slice(&self, span: Span) -> Result<&str, YamlError>
Returns the source slice for span, or a span-rich error when invalid.
§Errors
Returns an error when span is outside the source text or does not fall
on UTF-8 boundaries.
Sourcepub fn line_col(&self, offset: usize) -> LineCol
pub fn line_col(&self, offset: usize) -> LineCol
Converts a byte offset into a one-based line/column pair.
Sourcepub fn diagnostic_position(&self, diagnostic: &Diagnostic) -> LineCol
pub fn diagnostic_position(&self, diagnostic: &Diagnostic) -> LineCol
Returns the line/column pair for a diagnostic’s primary span.
Trait Implementations§
impl Eq for Source
impl StructuralPartialEq for Source
Auto Trait Implementations§
impl Freeze for Source
impl RefUnwindSafe for Source
impl Send for Source
impl Sync for Source
impl Unpin for Source
impl UnsafeUnpin for Source
impl UnwindSafe for Source
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more