[][src]Trait druid::text::format::Formatter

pub trait Formatter<T> {
    pub fn format(&self, value: &T) -> String;
pub fn validate_partial_input(
        &self,
        input: &str,
        sel: &Selection
    ) -> Validation;
pub fn value(&self, input: &str) -> Result<T, ValidationError>; pub fn format_for_editing(&self, value: &T) -> String { ... } }

A trait for types that create, interpret, and validate textual representations of values.

A formatter has two responsiblities: converting a value into an appropriate string representation, and attempting to convert a string back into the appropriate value.

In addition, a formatter performs validation on partial strings; that is, it determines whether or not a string represents a potentially valid value, even if it is not currently valid.

Required methods

pub fn format(&self, value: &T) -> String[src]

Return the string representation of this value.

pub fn validate_partial_input(&self, input: &str, sel: &Selection) -> Validation[src]

Determine whether the newly edited text is valid for this value type.

This always returns a Validation object which indicates if validation was successful or not, and which can also optionally, regardless of success or failure, include new text and selection values that should replace the current ones.

Replacing the text or selection during validation

Your Formatter may wish to change the current text or selection during editing for a number of reasons. For instance if validation fails, you may wish to allow editing to continue, but select the invalid region; alternatively you may consider input valid but want to transform it, such as by changing case or inserting spaces.

If you do not explicitly set replacement text, and validation is not successful, the edit will be ignored.

pub fn value(&self, input: &str) -> Result<T, ValidationError>[src]

The value represented by the input, or an error if the input is invalid.

This must return Ok() for any string created by format.

Loading content...

Provided methods

pub fn format_for_editing(&self, value: &T) -> String[src]

Return the string representation of this value, to be used during editing.

This can be used if you want the text to differ based on whether or not it is being edited; for instance you might display a dollar sign when not editing, but not display it during editing.

Loading content...

Implementors

impl<T> Formatter<T> for ParseFormatter<T> where
    T: FromStr,
    <T as FromStr>::Err: Error + 'static, 
[src]

Loading content...