[−][src]Derive Macro sanitizer_macros::Sanitize
#[derive(Sanitize)] { // Attributes available to this derive: #[sanitize] }
The Sanitize derive macro implements the Sanitize trait for you.
The trait only has a single associated function called sanitize
which edits the fields based on the sanitizer you specified in
the helper attributes
Example
use sanitizer::prelude::*; #[derive(Sanitize)] struct User { #[sanitize(trim)] name: String } fn main() { let mut instance = User { name: String::from("John, Doe ") }; instance.sanitize(); assert_eq!(instance.name, "John, Doe"); }
Available sanitizers
- trim: Trims the string.
- numeric: Remove numeric items from the string.
- alphanumeric: Remove alphanumeric items from the string.
- lower_case: Convert input to lower case.
- upper_case: Convert input to upper case.
- camel_case: Convert input to camel case.
- snake_case: Convert input to snake case.
- e164: Convert a valid phone number to the e164 international standard, panic if invalid phone number.
- clamp(min, max): Limit an integer input to this region of min to max.
- clamp(max): Cut the string if it exceeds max.
- screaming_snake_case: Convert input to screaming snake case.