[][src]Trait rustyline::validate::Validator

pub trait Validator {
    fn validate(
        &self,
        ctx: &mut ValidationContext<'_>
    ) -> Result<ValidationResult> { ... }
fn validate_while_typing(&self) -> bool { ... } }

This trait provides an extension interface for determining whether the current input buffer is valid. Rustyline uses the method provided by this trait to decide whether hitting the enter key will end the current editing session and return the current line buffer to the caller of Editor::readline or variants.

Provided methods

fn validate(&self, ctx: &mut ValidationContext<'_>) -> Result<ValidationResult>

Takes the currently edited input and returns a ValidationResult indicating whether it is valid or not along with an option message to display about the result. The most common validity check to implement is probably whether the input is complete or not, for instance ensuring that all delimiters are fully balanced.

If you implement more complex validation checks it's probably a good idea to also implement a Hinter to provide feedback about what is invalid.

For auto-correction like a missing closing quote or to reject invalid char while typing, the input will be mutable (TODO).

fn validate_while_typing(&self) -> bool

Configure whether validation is performed while typing or only when user presses the Enter key.

Default is false.

Loading content...

Implementations on Foreign Types

impl Validator for ()[src]

impl<'v, V: ?Sized + Validator> Validator for &'v V[src]

Loading content...

Implementors

Loading content...