Trait parsimonious::Function
[−]
[src]
pub trait Function<T> { type Output; fn apply(&self, arg: T) -> 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: CharacterParser<AlphaNumeric> = character(AlphaNumeric);
Here, we can name the type of the parser CharacterParser<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, T> Function<(S1, S2)> for Function2<F> where
F: Fn(S1, S2) -> T,impl<F, S1, S2, S3, T> Function<((S1, S2), S3)> for Function3<F> where
F: Fn(S1, S2, S3) -> T,impl<F, S1, S2, S3, S4, T> Function<(((S1, S2), S3), S4)> for Function4<F> where
F: Fn(S1, S2, S3, S4) -> T,impl<F, S1, S2, S3, S4, S5, T> Function<((((S1, S2), S3), S4), S5)> for Function5<F> where
F: Fn(S1, S2, S3, S4, S5) -> T,impl<F, S, T, E> Function<Result<S, E>> for Try<F> where
F: Function<S, Output = Result<T, E>>,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<F, S, T> Function<S> for F where
F: Fn(S) -> T,