Skip to main content

ScalarStyle

Enum ScalarStyle 

Source
#[non_exhaustive]
pub enum ScalarStyle {
#[non_exhaustive]
Plain { implicit: bool, },
#[non_exhaustive]
SingleQuoted,
#[non_exhaustive]
DoubleQuoted,
#[non_exhaustive]
Literal { syntax: Option<BlockScalarSyntax>, },
#[non_exhaustive]
Folded { syntax: Option<BlockScalarSyntax>, }, }
Expand description

The source notation and applicable syntax metadata of a YAML scalar.

Inspect styles with matches!, if let, or match, using { .. } even for variants that currently have no fields. The rest pattern ignores metadata you do not need and lets the library add fields later without changing your code. The enum and every variant are non-exhaustive, so a complete match also needs a fallback arm.

Normal builds provide no equality, ordering, or hashing. Comparing every style field would make classification depend on all present and future metadata. Match the variant instead, then inspect the fields relevant to your use case. Self::kind returns a comparable, fieldless category when a map key or ordering is needed. The opt-in test_equality feature compares only the notation category for tests. It ignores the implicit flag and all extended_details fields: source information may be absent on synthetic values, and enabling optional capture through another dependency must not change equality. Compare implicit or syntax explicitly when testing those details. Metadata defaults are not equality wildcards; source metadata is always excluded so equality remains transitive.

Constructors create styles for synthetic events and alternative parser implementations. They are independent of classification: use patterns to inspect the resulting values. Their signatures are the same with and without extended_details. The feature adds optional block syntax fields and builders; synthetic block styles start without known source syntax. Omitted-node identity and Self::is_omitted are available in every build. This keeps construction independent of future metadata additions.

use granit_parser::{Parser, ScalarStyle};
let (event, _) = Parser::new_from_str("value").nth(2).unwrap().unwrap();
let (_, style) = event.scalar().unwrap();
assert!(matches!(style, ScalarStyle::Plain { .. }));
assert!(!matches!(style, ScalarStyle::SingleQuoted { .. }));

Whole-style equality is intentionally unavailable by default:

ⓘ
use granit_parser::ScalarStyle;
fn equal_styles(left: ScalarStyle, right: ScalarStyle) -> bool {
    left == right
}

Styles are not hash keys; use ScalarKind when only the notation category matters:

ⓘ
use granit_parser::ScalarStyle;
fn require_hash<T: core::hash::Hash>() {}
require_hash::<ScalarStyle>();

Non-exhaustive variants cannot be constructed directly outside this crate:

ⓘ
use granit_parser::ScalarStyle;
let style = ScalarStyle::SingleQuoted;

Use a constructor to create a synthetic style:

use granit_parser::ScalarStyle;
let style = ScalarStyle::literal();
assert!(matches!(style, ScalarStyle::Literal { .. }));

Variant patterns must allow future fields:

ⓘ
use granit_parser::ScalarStyle;
fn inspect(style: ScalarStyle) {
    if let ScalarStyle::Literal {} = style {}
}

Variants (Non-exhaustive)§

This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

#[non_exhaustive]
Plain

A plain scalar or a synthesized empty node.

Fields

This variant is marked as non-exhaustive
Non-exhaustive enum variants could have additional fields added in future. Therefore, non-exhaustive enum variants cannot be constructed in external crates and cannot be matched against.
§implicit: bool

Whether the parser synthesized an omitted node instead of reading scalar text.

Explicit tags and anchors can decorate an omitted node. Written empty quoted or block scalars have their own styles and are never implicit plain scalars. This distinction is available without extended_details.

§

#[non_exhaustive]
SingleQuoted

A single-quoted scalar.

§

#[non_exhaustive]
DoubleQuoted

A double-quoted scalar.

§

#[non_exhaustive]
Literal

A literal block, with no escape processing or line folding.

Fields

This variant is marked as non-exhaustive
Non-exhaustive enum variants could have additional fields added in future. Therefore, non-exhaustive enum variants cannot be constructed in external crates and cannot be matched against.
§syntax: Option<BlockScalarSyntax>

Header syntax relative to the accompanying scalar span, when known.

Parsed block styles contain Some when all details fit in u32; synthetic styles and unrepresentable parsed details use None. Available only with extended_details.

§

#[non_exhaustive]
Folded

A folded block, whose line breaks are subject to YAML line folding.

Fields

This variant is marked as non-exhaustive
Non-exhaustive enum variants could have additional fields added in future. Therefore, non-exhaustive enum variants cannot be constructed in external crates and cannot be matched against.
§syntax: Option<BlockScalarSyntax>

Header syntax relative to the accompanying scalar span, when known.

Parsed block styles contain Some when all details fit in u32; synthetic styles and unrepresentable parsed details use None. Available only with extended_details.

Implementations§

Source§

impl ScalarStyle

Source

pub const fn plain() -> Self

Return the style of explicitly written plain scalar text.

Source

pub const fn implicit_plain() -> Self

Return the style of an omitted node synthesized by a parser.

Source

pub const fn with_implicit(self, implicit: bool) -> Self

Set whether a plain scalar represents an omitted node.

Other styles are returned unchanged because this detail applies only to plain scalars.

Source

pub const fn single_quoted() -> Self

Return single-quoted notation.

Source

pub const fn double_quoted() -> Self

Return double-quoted notation.

Source

pub const fn literal() -> Self

Return literal block style without known source-header syntax.

Source

pub const fn folded() -> Self

Return folded block style without known source-header syntax.

Source

pub const fn with_block_syntax(self, syntax: BlockScalarSyntax) -> Self

Attach known source-header syntax to a literal or folded style.

Other styles are returned unchanged because block-header syntax does not apply to them. Available only with extended_details.

use granit_parser::{BlockScalarSyntax, ScalarStyle};
let style = ScalarStyle::literal();
assert!(style.block_syntax().is_none());
let style = style.with_block_syntax(BlockScalarSyntax::default());
assert!(style.block_syntax().is_some());
Source

pub const fn kind(&self) -> ScalarKind

Return the notation category, ignoring source positions and all other metadata.

Source

pub const fn is_plain(&self) -> bool

Return whether this is plain notation, including synthesized empty nodes.

Equivalent to matches!(self, ScalarStyle::Plain { .. }).

Source

pub const fn is_omitted(&self) -> bool

Return whether the parser synthesized an omitted node rather than reading scalar text.

Written null spellings such as ~ and null, empty quoted strings, and empty block scalars return false. An omitted node can still have an explicit tag or anchor.

Source

pub const fn is_single_quoted(&self) -> bool

Return whether this is single-quoted notation.

Source

pub const fn is_double_quoted(&self) -> bool

Return whether this is double-quoted notation.

Source

pub const fn is_literal(&self) -> bool

Return whether this is literal block notation.

Source

pub const fn is_folded(&self) -> bool

Return whether this is folded block notation.

Source

pub const fn block_syntax(&self) -> Option<&BlockScalarSyntax>

Return known block-header syntax for literal and folded scalars.

Returns None for other styles, synthetic block styles with no attached syntax, and parsed block styles whose header distances or content indentation exceed u32::MAX. Available only with extended_details.

Trait Implementations§

Source§

impl Clone for ScalarStyle

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 ScalarStyle

Source§

impl Debug for ScalarStyle

Source§

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

Formats the value using the given formatter. 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.