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
fn apply(&self, arg: T) -> Self::Output
Implementors
impl<F, S, T> Function<S> for F where F: Fn(S) -> T