Trait parsell::Function
[−]
[src]
pub trait Function<S> { type Output; fn apply(&self, arg: S) -> Self::Output; }
A trait for one-argument functions.
This trait is just the same as Fn(T) -> U
, but can be implemented by a struct.
This is useful, as it allows the function type to be named, for example
struct AlphaNumeric; impl Function<char> for AlphaNumeric { type Output = bool; fn apply(&self, arg: char) -> bool { arg.is_alphanumeric() } } let parser: Character<AlphaNumeric> = character(AlphaNumeric);
Here, we can name the type of the parser Character<AlphaNumeric>
,
which would not be possible if character
took its argument as a Fn(T) -> U
,
since typeof
is not implemented in Rust.
At some point, Rust will probably get abstract return types,
at which point the main need for this type will go away.
Associated Types
type Output
Required Methods
Implementors
impl<F, S1, S2> Function<(S1, S2)> for Function2<F> where
F: Fn<(S1, S2)>,impl<F, S1, S2, S3> Function<((S1, S2), S3)> for Function3<F> where
F: Fn<(S1, S2, S3)>,impl<F, S1, S2, S3, S4> Function<(((S1, S2), S3), S4)> for Function4<F> where
F: Fn<(S1, S2, S3, S4)>,impl<F, S1, S2, S3, S4, S5> Function<((((S1, S2), S3), S4), S5)> for Function5<F> where
F: Fn<(S1, S2, S3, S4, S5)>,impl<F, S1, S2, S3, S4, S5, S6> Function<(((((S1, S2), S3), S4), S5), S6)> for Function6<F> where
F: Fn<(S1, S2, S3, S4, S5, S6)>,impl<F, S, E> Function<Result<S, E>> for Try<F> where
F: Function<S>,impl<S, E> Function<Result<S, E>> for TryDiscard
impl<S, T, E> Function<(Result<S, E>, T)> for TryZip
impl<S, T, E> Function<(S, Result<T, E>)> for ZipTry
impl<S, T, E> Function<(Result<S, E>, Result<T, E>)> for TryZipTry
impl<T, E> Function<Option<Result<T, E>>> for TryOpt
impl<T> Function<T> for MkSome
impl<F, S, T> Function<S> for IsSome<F> where
F: Function<S, Output = Option<T>>,impl<F, S, T> Function<S> for Unwrap<F> where
F: Function<S, Output = Option<T>>,impl<F, S, T> Function<S> for Dereference<F> where
F: for<'a> Function<&'a S, Output = T>,impl<S, T> Function<(S, T)> for First
impl<S, T> Function<(S, T)> for Second
impl<F, S> Function<S> for F where
F: Fn<(S,)>,