Skip to main content

SpanStringTokenizer

Struct SpanStringTokenizer 

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

Splits a string into tokens separated by white space and/or a single separator character, reading them as integers, doubles or raw slices.

Reading can fail in two distinct ways, mirrored by the try_read_* signatures: Ok(None) means “no (valid) value here”, Err means the input is malformed (empty token, doubled separator, trailing separator, …).

Implementations§

Source§

impl<'a> SpanStringTokenizer<'a>

Source

pub fn new(s: &'a str) -> Self

Creates a tokenizer using , as separator and the default error message.

Source

pub fn with_message(s: &'a str, exception_message: &'static str) -> Self

Creates a tokenizer using , as separator (the invariant-culture separator) and the given error message.

Source

pub fn with_separator( s: &'a str, separator: char, exception_message: Option<&'static str>, ) -> Self

Creates a tokenizer with an explicit separator and optional error message.

Source

pub fn current_token_index(&self) -> Option<usize>

Byte offset of the current token, or None when there is no current token.

Source

pub fn current_token(&self) -> Option<&'a str>

The current token, or None when there is no current token.

Source

pub fn current_token_span(&self) -> &'a str

The current token, or an empty slice when there is no current token.

Source

pub fn finish(&self) -> Result<(), FormatError>

Verifies that the whole input was consumed.

This is the counterpart of disposing the tokenizer in the reference implementation and must be called once reading is done.

Source

pub fn scope<T>( self, f: impl FnOnce(&mut Self) -> Result<T, FormatError>, ) -> Result<T, FormatError>

Runs f and then finish. An error from finish takes precedence over an error from f, exactly like an exception thrown while leaving a scoped-disposal block replaces the one in flight.

Source

pub fn try_read_int32(&mut self) -> Result<Option<i32>, FormatError>

Source

pub fn try_read_int32_with( &mut self, separator: Option<char>, ) -> Result<Option<i32>, FormatError>

Source

pub fn read_int32(&mut self) -> Result<i32, FormatError>

Source

pub fn read_int32_with( &mut self, separator: Option<char>, ) -> Result<i32, FormatError>

Source

pub fn try_read_double(&mut self) -> Result<Option<f64>, FormatError>

Source

pub fn try_read_double_with( &mut self, separator: Option<char>, ) -> Result<Option<f64>, FormatError>

Source

pub fn read_double(&mut self) -> Result<f64, FormatError>

Source

pub fn read_double_with( &mut self, separator: Option<char>, ) -> Result<f64, FormatError>

Source

pub fn try_read_string(&mut self) -> Result<Option<&'a str>, FormatError>

Same as try_read_span; tokens are borrowed slices.

Source

pub fn try_read_string_with( &mut self, separator: Option<char>, ) -> Result<Option<&'a str>, FormatError>

Source

pub fn read_string(&mut self) -> Result<&'a str, FormatError>

Same as read_span; tokens are borrowed slices.

Source

pub fn read_string_with( &mut self, separator: Option<char>, ) -> Result<&'a str, FormatError>

Source

pub fn try_read_span(&mut self) -> Result<Option<&'a str>, FormatError>

Source

pub fn try_read_span_with( &mut self, separator: Option<char>, ) -> Result<Option<&'a str>, FormatError>

Source

pub fn read_span(&mut self) -> Result<&'a str, FormatError>

Source

pub fn read_span_with( &mut self, separator: Option<char>, ) -> Result<&'a str, FormatError>

Trait Implementations§

Source§

impl<'a> Clone for SpanStringTokenizer<'a>

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<'a> Debug for SpanStringTokenizer<'a>

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> ClassDefaults for T
where T: ?Sized,

Source§

fn static_constructor()

The static constructor of a type: work done once per thread, after the properties of the type are registered and before its first instance exists (class handlers, affects_render, metadata overrides). 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.