pub struct Closure { /* private fields */ }Expand description
A Parse implementation whose behaviour is supplied by closures.
Reach for this instead of a full impl Parse when the parser is small, stateless, or a
one-off adapter. See the module docs for a complete example.
Implementations§
Source§impl Closure
impl Closure
Sourcepub fn new<N: AsRef<str>, F: AsRef<str>>(
name: N,
supported_format: F,
parser: BoxedParseFn,
) -> Self
pub fn new<N: AsRef<str>, F: AsRef<str>>( name: N, supported_format: F, parser: BoxedParseFn, ) -> Self
Build a closure-backed parser.
name— the parsernameused in error messages.supported_format— the single format extension this parser handles (widen later withClosure::with_format_list).parser— the closure run byparse.
The auto-detection probe defaults to abstaining (None); set one with
Closure::with_validator.
Sourcepub fn with_validator(self, validator: BoxedValidatorFn) -> Self
pub fn with_validator(self, validator: BoxedValidatorFn) -> Self
Attach an auto-detection probe (see BoxedValidatorFn) used when a payload has no format
hint.
Sourcepub fn with_format_list<N: AsRef<str>>(self, format_list: &[N]) -> Self
pub fn with_format_list<N: AsRef<str>>(self, format_list: &[N]) -> Self
Replace the list of format extensions this parser handles (e.g. ["yml", "yaml"]).
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for Closure
impl !Send for Closure
impl !Sync for Closure
impl !UnwindSafe for Closure
impl Freeze for Closure
impl Unpin for Closure
impl UnsafeUnpin for Closure
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
Mutably borrows from an owned value. Read more