Skip to main content

BlockScalarSyntax

Struct BlockScalarSyntax 

Source
#[non_exhaustive]
pub struct BlockScalarSyntax { pub header_chars_before_span: u32, pub header_bytes_before_span: u32, pub chomping: Chomping, pub indentation_indicator: Option<u8>, pub digit_first: bool, pub content_indent: u32, }
Expand description

Source syntax attached to a literal or folded block scalar.

Available only with extended_details.

Coordinates are relative to the start of the accompanying scalar span. Keep that span together with this value: rebasing or replacing its start invalidates these distances. The ordinary scalar span retains its existing meaning, which need not include the header. This type does not store another crate::Marker or retain borrowed source text.

The header ranges cover | or > and its adjacent indicators, excluding whitespace, comments, and the header line break. Character and byte distances differ when, for example, a header comment contains Unicode. Use Self::header_byte_range to inspect byte distances when available. Indicator offsets are computed from the chomping mode, indentation digit, and their order. Distances and content indentation use u32. If a parsed value cannot fit, the scalar’s syntax is None; scalar decoding and the accompanying span remain available.

Normal builds provide no equality, ordering, or hashing. Inspect the individual fields relevant to your use case. The opt-in test_equality feature enables equality for testing; it ignores optional byte distances, like crate::Marker, and irrelevant indicator order. This is an explicit comparison of source syntax. Equality of ScalarStyle, events, and tokens instead ignores this metadata altogether, keeping output comparisons independent of whether extended_details is enabled. Comparing synthetic syntax with parsed syntax is intentionally unavailable by default:

ⓘ
use granit_parser::BlockScalarSyntax;
let syntax = BlockScalarSyntax::default();
let _ = syntax == BlockScalarSyntax::default();

Fields (Non-exhaustive)§

This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.
§header_chars_before_span: u32

Character distance backwards from the scalar span’s start to | or >.

§header_bytes_before_span: u32

Byte distance backwards from the scalar span’s start to | or >.

Meaningful only when the accompanying span’s start has a byte offset. Otherwise zero.

§chomping: Chomping

Chomping mode selected by the header.

§indentation_indicator: Option<u8>

Explicit indentation digit (1..=9), or None when indentation was inferred.

§digit_first: bool

Whether the indentation digit precedes the chomping sign when both are present.

Ignored when either indicator is absent, including by test_equality comparisons. Parsed headers set this to false in that case.

§content_indent: u32

Effective number of leading indentation spaces removed from content lines.

This is an absolute content indentation level, not the explicit indentation digit. For an inferred header ending at EOF before its line break, this reports the minimum level required by the enclosing block. At the root it is zero by default, or one when crate::Options::block_scalar_indent_at_least_one is enabled.

Implementations§

Source§

impl BlockScalarSyntax

Source

pub const fn new( chomping: Chomping, indentation_indicator: Option<u8>, content_indent: usize, ) -> Option<Self>

Construct synthetic syntax whose header begins at the accompanying span’s start.

  • chomping selects clipping, stripping, or keeping trailing line breaks.
  • indentation_indicator is the optional explicit digit, which must be in 1..=9.
  • content_indent is the effective absolute content indentation level.

Returns None for an invalid digit or content indentation larger than u32::MAX. Otherwise the sign precedes the digit when both are present, and both backwards distances are zero. Set the public fields to describe a different indicator order or a header preceding the scalar span.

Source

pub const fn header_len(&self) -> usize

Return the header-indicator length in both characters and bytes, excluding whitespace.

Parsed headers contain one to three ASCII characters.

Source

pub const fn chomping_offset(&self) -> Option<u8>

Return the chomping sign’s offset from the header start, or None for clipping.

Offsets are the same in characters and bytes: a block header contains only ASCII.

Source

pub const fn indentation_offset(&self) -> Option<u8>

Return the indentation digit’s offset from the header start, or None if inferred.

Offsets are the same in characters and bytes: a block header contains only ASCII.

Source

pub fn header_char_range(&self, span: &Span) -> Option<Range<usize>>

Return the header’s character-index range using its accompanying scalar span.

Returns None if the coordinates underflow or overflow. The caller must supply the original matching span; arithmetic checks cannot detect every mismatched span.

Source

pub fn header_byte_range(&self, span: &Span) -> Option<Range<usize>>

Return the header’s byte range using its accompanying scalar span.

Returns None for inputs without byte offsets or if coordinates underflow or overflow. The caller must supply the original matching span.

Source

pub fn chomping_char_range(&self, span: &Span) -> Option<Range<usize>>

Return the explicit chomping sign’s character range, or None if absent/unavailable.

Source

pub fn chomping_byte_range(&self, span: &Span) -> Option<Range<usize>>

Return the explicit chomping sign’s byte range, or None if absent/unavailable.

Source

pub fn indentation_char_range(&self, span: &Span) -> Option<Range<usize>>

Return the explicit indentation digit’s character range, or None if absent/unavailable.

Source

pub fn indentation_byte_range(&self, span: &Span) -> Option<Range<usize>>

Return the explicit indentation digit’s byte range, or None if absent/unavailable.

Source

pub fn header_slice<'source>( &self, span: &Span, source: &'source str, ) -> Option<&'source str>

Return the raw header indicators from the original source.

  • span is the original accompanying scalar span.
  • source is the complete original UTF-8 source, using the span’s coordinate origin.

Returns None when byte positions are unavailable or outside valid source boundaries.

Trait Implementations§

Source§

impl Clone for BlockScalarSyntax

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 Copy for BlockScalarSyntax

Source§

impl Debug for BlockScalarSyntax

Source§

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

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

impl Default for BlockScalarSyntax

Source§

fn default() -> Self

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

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.