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>
impl<'a> SpanStringTokenizer<'a>
Sourcepub fn new(s: &'a str) -> Self
pub fn new(s: &'a str) -> Self
Creates a tokenizer using , as separator and the default error message.
Sourcepub fn with_message(s: &'a str, exception_message: &'static str) -> Self
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.
Sourcepub fn with_separator(
s: &'a str,
separator: char,
exception_message: Option<&'static str>,
) -> Self
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.
Sourcepub fn current_token_index(&self) -> Option<usize>
pub fn current_token_index(&self) -> Option<usize>
Byte offset of the current token, or None when there is no current token.
Sourcepub fn current_token(&self) -> Option<&'a str>
pub fn current_token(&self) -> Option<&'a str>
The current token, or None when there is no current token.
Sourcepub fn current_token_span(&self) -> &'a str
pub fn current_token_span(&self) -> &'a str
The current token, or an empty slice when there is no current token.
Sourcepub fn finish(&self) -> Result<(), FormatError>
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.
Sourcepub fn scope<T>(
self,
f: impl FnOnce(&mut Self) -> Result<T, FormatError>,
) -> Result<T, FormatError>
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.
pub fn try_read_int32(&mut self) -> Result<Option<i32>, FormatError>
pub fn try_read_int32_with( &mut self, separator: Option<char>, ) -> Result<Option<i32>, FormatError>
pub fn read_int32(&mut self) -> Result<i32, FormatError>
pub fn read_int32_with( &mut self, separator: Option<char>, ) -> Result<i32, FormatError>
pub fn try_read_double(&mut self) -> Result<Option<f64>, FormatError>
pub fn try_read_double_with( &mut self, separator: Option<char>, ) -> Result<Option<f64>, FormatError>
pub fn read_double(&mut self) -> Result<f64, FormatError>
pub fn read_double_with( &mut self, separator: Option<char>, ) -> Result<f64, FormatError>
Sourcepub fn try_read_string(&mut self) -> Result<Option<&'a str>, FormatError>
pub fn try_read_string(&mut self) -> Result<Option<&'a str>, FormatError>
Same as try_read_span; tokens are borrowed slices.
pub fn try_read_string_with( &mut self, separator: Option<char>, ) -> Result<Option<&'a str>, FormatError>
Sourcepub fn read_string(&mut self) -> Result<&'a str, FormatError>
pub fn read_string(&mut self) -> Result<&'a str, FormatError>
Same as read_span; tokens are borrowed slices.
pub fn read_string_with( &mut self, separator: Option<char>, ) -> Result<&'a str, FormatError>
pub fn try_read_span(&mut self) -> Result<Option<&'a str>, FormatError>
pub fn try_read_span_with( &mut self, separator: Option<char>, ) -> Result<Option<&'a str>, FormatError>
pub fn read_span(&mut self) -> Result<&'a str, FormatError>
pub fn read_span_with( &mut self, separator: Option<char>, ) -> Result<&'a str, FormatError>
Trait Implementations§
Source§impl<'a> Clone for SpanStringTokenizer<'a>
impl<'a> Clone for SpanStringTokenizer<'a>
Auto Trait Implementations§
impl<'a> Freeze for SpanStringTokenizer<'a>
impl<'a> RefUnwindSafe for SpanStringTokenizer<'a>
impl<'a> Send for SpanStringTokenizer<'a>
impl<'a> Sync for SpanStringTokenizer<'a>
impl<'a> Unpin for SpanStringTokenizer<'a>
impl<'a> UnsafeUnpin for SpanStringTokenizer<'a>
impl<'a> UnwindSafe for SpanStringTokenizer<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> ClassDefaults for Twhere
T: ?Sized,
impl<T> ClassDefaults for Twhere
T: ?Sized,
Source§fn static_constructor()
fn static_constructor()
affects_render, metadata
overrides). Read more