pub trait Validator {
// Provided methods
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§
sourcefn validate(&self, ctx: &mut ValidationContext<'_>) -> Result<ValidationResult>
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).
sourcefn validate_while_typing(&self) -> bool
fn validate_while_typing(&self) -> bool
Configure whether validation is performed while typing or only when user presses the Enter key.
Default is false
.
This feature is not yet implemented, so this function is currently a no-op