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

Required Methods

Implementors