StylesParser

Struct StylesParser 

Source
pub struct StylesParser<'a> { /* private fields */ }
Expand description

Parser for [V4+ Styles] section content

Parses format definitions and style entries from the styles section. Uses format mapping to handle different field orderings and missing fields.

§Performance

  • Time complexity: O(n * m) for n styles and m fields per style
  • Memory: Zero allocations via lifetime-generic spans
  • Target: <1ms for typical style sections with 50 styles

Implementations§

Source§

impl<'a> StylesParser<'a>

Source

pub fn parse_style_line( line: &'a str, format: &[&'a str], line_number: u32, ) -> Result<Style<'a>, ParseError>

Parse a single style line

Parses a single style definition line using the provided format specification. This method is exposed for incremental parsing support.

§Arguments
  • line - The style line to parse (without “Style:” prefix)
  • format - The format fields from the Format line
  • line_number - The line number for error reporting
§Returns

Parsed Style or error if the line is malformed

§Errors

Returns ParseError::InsufficientFields if the line has fewer fields than expected by format

Source

pub fn new(source: &'a str, start_position: usize, start_line: usize) -> Self

Create new styles parser for source text

§Arguments
  • source - Source text to parse
  • start_position - Starting byte position in source
  • start_line - Starting line number for error reporting
Source

pub fn with_format( source: &'a str, format: &[&'a str], start_position: usize, start_line: u32, ) -> Self

Create a new parser with a pre-known format for incremental parsing

Source

pub fn parse(self) -> ParseResult<SectionParseResult<'a>>

Parse styles section content

Returns the parsed section and any issues encountered during parsing. Handles Format line parsing and style entry validation.

§Returns

Tuple of (parsed_section, format_fields, parse_issues, final_position, final_line)

§Errors

Returns an error if the styles section contains malformed format lines or other unrecoverable syntax errors.

Auto Trait Implementations§

§

impl<'a> Freeze for StylesParser<'a>

§

impl<'a> RefUnwindSafe for StylesParser<'a>

§

impl<'a> Send for StylesParser<'a>

§

impl<'a> Sync for StylesParser<'a>

§

impl<'a> Unpin for StylesParser<'a>

§

impl<'a> UnwindSafe for StylesParser<'a>

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.