pub trait DataTransformer: Send + Sync {
// Required methods
fn transform(&self, model: &str) -> Result<String, FormError>;
fn reverse_transform(&self, view: &str) -> Result<String, FormError>;
}Expand description
Converts between the HTML view string and the model string stored on the field.
§Examples
use serenade_form::{BoolToStringTransformer, DataTransformer};
let t = BoolToStringTransformer::default();
assert_eq!(t.reverse_transform("1").unwrap(), "1");
assert_eq!(t.reverse_transform("").unwrap(), "0");
assert_eq!(t.transform("1").unwrap(), "1");Required Methods§
Sourcefn transform(&self, model: &str) -> Result<String, FormError>
fn transform(&self, model: &str) -> Result<String, FormError>
Model value → view string used in HTML.
§Errors
Returns FormError::Transform when the model value cannot be shown.
Sourcefn reverse_transform(&self, view: &str) -> Result<String, FormError>
fn reverse_transform(&self, view: &str) -> Result<String, FormError>
Submitted view string → model value stored on the field.
§Errors
Returns FormError::Transform when the view value is invalid.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".