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

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

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

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).

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

Default is false.

Implementations on Foreign Types

Implementors