Skip to main content

TokenType

Enum TokenType 

Source
#[non_exhaustive]
pub enum TokenType<'input> {
Show 23 variants
#[non_exhaustive]
StreamStart,
#[non_exhaustive]
StreamEnd,
#[non_exhaustive]
VersionDirective { major: u32, minor: u32, },
#[non_exhaustive]
TagDirective { handle: Cow<'input, str>, prefix: Cow<'input, str>, },
#[non_exhaustive]
DocumentStart,
#[non_exhaustive]
DocumentEnd,
#[non_exhaustive]
BlockSequenceStart,
#[non_exhaustive]
BlockMappingStart,
#[non_exhaustive]
BlockEnd,
#[non_exhaustive]
FlowSequenceStart,
#[non_exhaustive]
FlowSequenceEnd,
#[non_exhaustive]
FlowMappingStart,
#[non_exhaustive]
FlowMappingEnd,
#[non_exhaustive]
BlockEntry,
#[non_exhaustive]
FlowEntry,
#[non_exhaustive]
Key,
#[non_exhaustive]
Value,
#[non_exhaustive]
Alias { name: Cow<'input, str>, },
#[non_exhaustive]
Anchor { name: Cow<'input, str>, },
#[non_exhaustive]
Tag { handle: Cow<'input, str>, suffix: Cow<'input, str>, },
#[non_exhaustive]
Scalar { style: ScalarStyle, value: Cow<'input, str>, },
#[non_exhaustive]
Comment { comment: Comment<'input>, },
#[non_exhaustive]
ReservedDirective { name: String, parameters: Vec<String>, },
}
Expand description

The contents of a scanner token.

Use matches!, if let, or match with { .. } to inspect a token variant. Every variant is non-exhaustive, even if it currently has no fields, so the library can add metadata without changing those patterns. A complete match also needs a fallback arm. Normal builds provide no whole-token equality; the opt-in test_equality feature enables equality for tests. It compares token variants and payloads, but scalar styles compare only their notation category, ignoring optional extended_details source metadata. This keeps equality independent of whether a dependency enables metadata capture; compare syntax fields explicitly when they matter. Constructors support synthetic token streams and scanner adapters.

use granit_parser::{Scanner, StrInput, TokenType};
let token = Scanner::new(StrInput::new("value")).next().unwrap().unwrap();
assert!(matches!(token.token_type(), TokenType::StreamStart { .. }));
ⓘ
use granit_parser::TokenType;
fn equal_tokens(left: TokenType<'_>, right: TokenType<'_>) -> bool {
    left == right
}
use granit_parser::TokenType;
let token = TokenType::alias("name".into());
assert!(matches!(token, TokenType::Alias { name, .. } if name == "name"));

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]
StreamStart

Start of the stream.

§

#[non_exhaustive]
StreamEnd

End of the stream.

§

#[non_exhaustive]
VersionDirective

A YAML version directive.

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.
§major: u32

Major version number.

§minor: u32

Minor version number.

§

#[non_exhaustive]
TagDirective

A YAML tag directive.

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.
§handle: Cow<'input, str>

Tag handle.

§prefix: Cow<'input, str>

Tag URI prefix.

§

#[non_exhaustive]
DocumentStart

Explicit document start marker (---).

§

#[non_exhaustive]
DocumentEnd

Explicit document end marker (...).

§

#[non_exhaustive]
BlockSequenceStart

Start of a block sequence.

§

#[non_exhaustive]
BlockMappingStart

Start of a block mapping.

§

#[non_exhaustive]
BlockEnd

End of a block collection.

§

#[non_exhaustive]
FlowSequenceStart

Opening [ of a flow sequence.

§

#[non_exhaustive]
FlowSequenceEnd

Closing ] of a flow sequence.

§

#[non_exhaustive]
FlowMappingStart

Opening { of a flow mapping.

§

#[non_exhaustive]
FlowMappingEnd

Closing } of a flow mapping.

§

#[non_exhaustive]
BlockEntry

Block sequence entry indicator.

§

#[non_exhaustive]
FlowEntry

Flow collection entry separator.

§

#[non_exhaustive]
Key

Mapping key indicator.

§

#[non_exhaustive]
Value

Mapping value indicator.

§

#[non_exhaustive]
Alias

Alias name without the leading *.

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.
§name: Cow<'input, str>

Original name without an indicator.

§

#[non_exhaustive]
Anchor

Anchor name without the leading &.

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.
§name: Cow<'input, str>

Original name without an indicator.

§

#[non_exhaustive]
Tag

A YAML tag.

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.
§handle: Cow<'input, str>

Tag handle.

§suffix: Cow<'input, str>

Tag suffix.

§

#[non_exhaustive]
Scalar

A decoded YAML scalar and its source syntax.

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.
§style: ScalarStyle

Scalar source syntax.

§value: Cow<'input, str>

Decoded scalar value.

§

#[non_exhaustive]
Comment

A source comment, including its placement hint.

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.
§comment: Comment<'input>

Captured comment metadata.

§

#[non_exhaustive]
ReservedDirective

A reserved directive and its whitespace-separated parameters.

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.
§name: String

Original name without an indicator.

§parameters: Vec<String>

Directive parameters split on YAML whitespace.

Implementations§

Source§

impl<'input> TokenType<'input>

Source

pub const fn stream_start() -> Self

Return a Self::StreamStart token payload.

Source

pub const fn stream_end() -> Self

Return a Self::StreamEnd token payload.

Source

pub const fn document_start() -> Self

Return a Self::DocumentStart token payload.

Source

pub const fn document_end() -> Self

Return a Self::DocumentEnd token payload.

Source

pub const fn block_sequence_start() -> Self

Return a Self::BlockSequenceStart token payload.

Source

pub const fn block_mapping_start() -> Self

Return a Self::BlockMappingStart token payload.

Source

pub const fn block_end() -> Self

Return a Self::BlockEnd token payload.

Source

pub const fn flow_sequence_start() -> Self

Return a Self::FlowSequenceStart token payload.

Source

pub const fn flow_sequence_end() -> Self

Return a Self::FlowSequenceEnd token payload.

Source

pub const fn flow_mapping_start() -> Self

Return a Self::FlowMappingStart token payload.

Source

pub const fn flow_mapping_end() -> Self

Return a Self::FlowMappingEnd token payload.

Source

pub const fn block_entry() -> Self

Return a Self::BlockEntry token payload.

Source

pub const fn flow_entry() -> Self

Return a Self::FlowEntry token payload.

Source

pub const fn key() -> Self

Return a Self::Key token payload.

Source

pub const fn value() -> Self

Return a Self::Value token payload.

Source

pub fn version_directive(major: u32, minor: u32) -> Self

Return a Self::VersionDirective token payload.

  • major: Major version number.
  • minor: Minor version number.
Source

pub fn tag_directive(handle: Cow<'input, str>, prefix: Cow<'input, str>) -> Self

Return a Self::TagDirective token payload.

  • handle: Tag handle.
  • prefix: Tag URI prefix.
Source

pub fn alias(name: Cow<'input, str>) -> Self

Return a Self::Alias token payload.

  • name: Original name without an indicator.
Source

pub fn anchor(name: Cow<'input, str>) -> Self

Return a Self::Anchor token payload.

  • name: Original name without an indicator.
Source

pub fn tag(handle: Cow<'input, str>, suffix: Cow<'input, str>) -> Self

Return a Self::Tag token payload.

  • handle: Tag handle.
  • suffix: Tag suffix.
Source

pub fn scalar(style: ScalarStyle, value: Cow<'input, str>) -> Self

Return a Self::Scalar token payload.

  • style: Scalar source syntax.
  • value: Decoded scalar value.
Source

pub fn comment(comment: Comment<'input>) -> Self

Return a Self::Comment token payload.

  • comment: Captured comment metadata.
Source

pub fn reserved_directive(name: String, parameters: Vec<String>) -> Self

Return a Self::ReservedDirective token payload.

  • name: Original name without an indicator.
  • parameters: Directive parameters split on YAML whitespace.

Trait Implementations§

Source§

impl<'input> Clone for TokenType<'input>

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<'input> Debug for TokenType<'input>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'input> Forget for TokenType<'input>

§

impl<'input> Freeze for TokenType<'input>

§

impl<'input> Move for TokenType<'input>

§

impl<'input> RefUnwindSafe for TokenType<'input>

§

impl<'input> Send for TokenType<'input>
where &'input str: Send, String: Send, RawVecInner: Send,

§

impl<'input> Sync for TokenType<'input>
where String: Sync, RawVecInner: Sync,

§

impl<'input> Unpin for TokenType<'input>
where &'input str: Unpin, String: Unpin, *const u8 is !null: Unpin,

§

impl<'input> UnsafeUnpin for TokenType<'input>

§

impl<'input> UnwindSafe for TokenType<'input>
where &'input str: UnwindSafe, String: UnwindSafe, RawVecInner: UnwindSafe,

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.