FromStrBuilder

Struct FromStrBuilder 

Source
pub struct FromStrBuilder { /* private fields */ }
Expand description

A struct which will try to parse a string into a Value. This can be configured with custom parsers to extend what we’re able to parse into a Value.

Implementations§

Source§

impl FromStrBuilder

Source

pub fn add_custom_parser<F>(self, f: F) -> Self
where F: Fn(&mut &str) -> Option<Result<Value<()>, ParseError>> + 'static,

Add a custom parser. A custom parser is a function which is given a mutable string reference and will:

  • return None if the string given is not applicable,
  • return Some(Ok(value)) if we can successfully parse a value from the string. In this case, the parser should update the &mut str it’s given to consume however much was parsed.
  • return Some(Err(error)) if the string given looks like a match, but something went wrong in trying to properly parse it. In this case, parsing will stop immediately and this error will be returned, so use this sparingly, as other parsers may be able to successfully parse what this one has failed to parse. No additional tokens will be consumed if an error occurs.
Source

pub fn parse<'a>(&self, s: &'a str) -> (Result<Value<()>, ParseError>, &'a str)

Attempt to parse the string provided into a value, returning any error that occurred while attempting to do so, as well as the rest of the string that was not consumed by this parsing.

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> 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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.
Source§

impl<T> JsonSchemaMaybe for T