SpanStringTokenizer
struct · ferroui-base · v0.5.0
struct SpanStringTokenizer<'a>
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, ...).
Members
newwith_messagewith_separatorcurrent_token_indexcurrent_tokencurrent_token_spanfinishscopetry_read_int32try_read_int32_withread_int32read_int32_withtry_read_doubletry_read_double_withread_doubleread_double_withtry_read_stringtry_read_string_withread_stringread_string_withtry_read_spantry_read_span_withread_spanread_span_with
new
fn new(s: &'a str) -> Self
Creates a tokenizer using , as separator and the default error message.
with_message
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.
with_separator
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.
current_token_index
fn current_token_index(self: &Self) -> Option<usize>
Byte offset of the current token, or None when there is no current token.
current_token
fn current_token(self: &Self) -> Option<&'a str>
The current token, or None when there is no current token.
current_token_span
fn current_token_span(self: &Self) -> &'a str
The current token, or an empty slice when there is no current token.
finish
fn finish(self: &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.
scope
fn scope<T>(self: 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.
try_read_int32
fn try_read_int32(self: &mut Self) -> Result<Option<i32>, FormatError>
try_read_int32_with
fn try_read_int32_with(self: &mut Self, separator: Option<char>) -> Result<Option<i32>, FormatError>
read_int32
fn read_int32(self: &mut Self) -> Result<i32, FormatError>
read_int32_with
fn read_int32_with(self: &mut Self, separator: Option<char>) -> Result<i32, FormatError>
try_read_double
fn try_read_double(self: &mut Self) -> Result<Option<f64>, FormatError>
try_read_double_with
fn try_read_double_with(self: &mut Self, separator: Option<char>) -> Result<Option<f64>, FormatError>
read_double
fn read_double(self: &mut Self) -> Result<f64, FormatError>
read_double_with
fn read_double_with(self: &mut Self, separator: Option<char>) -> Result<f64, FormatError>
try_read_string
fn try_read_string(self: &mut Self) -> Result<Option<&'a str>, FormatError>
Same as try_read_span; tokens are borrowed slices.
try_read_string_with
fn try_read_string_with(self: &mut Self, separator: Option<char>) -> Result<Option<&'a str>, FormatError>
read_string
fn read_string(self: &mut Self) -> Result<&'a str, FormatError>
Same as read_span; tokens are borrowed slices.
read_string_with
fn read_string_with(self: &mut Self, separator: Option<char>) -> Result<&'a str, FormatError>
try_read_span
fn try_read_span(self: &mut Self) -> Result<Option<&'a str>, FormatError>
try_read_span_with
fn try_read_span_with(self: &mut Self, separator: Option<char>) -> Result<Option<&'a str>, FormatError>
read_span
fn read_span(self: &mut Self) -> Result<&'a str, FormatError>
read_span_with
fn read_span_with(self: &mut Self, separator: Option<char>) -> Result<&'a str, FormatError>
Trait implementations
SendSyncFreezeUnsafeUnpinUnpinUnwindSafeRefUnwindSafeClassDefaultsBorrow<T>BorrowMut<T>CloneToUninitInto<U>From<T>TryInto<U>TryFrom<U>AnyToOwnedErasedDestructorIntoEitherCloneDebug
Availability
Extracted for aarch64-apple-darwin. Cargo features are listed in the crate index.