Crate sanitizer[][src]

The Sanitizer crate helps in sanitizing structured data by providing macros and data structures to perform sanitization on fields.

Basic usage

If you want your incoming data which is serialised to a structure to be sanitized then first of all, you make a struct and derive the Sanitize trait on it. The macro will implement the trait for you all you have to do now is to call the sanitize method on the trait

use sanitizer::prelude::*;

struct User {
	name: String,
	#[sanitize(trim, lower_case)]
	email: String

fn main() {
	let mut instance = User {
		name: String::from("   John Doe123 "),
		email: String::from("")
	assert_eq!(, "John Doe123");
	assert_eq!(, "");

To see a list of available sanitizers, check the sanitizer-macros crate



Bring all the sanitizers, the derive macro, and the Sanitize trait in scope



The IntSanitizer structure is a wrapper over a type T which is to be sanitized, T can be anything that’s PartialOrd


The Sanitizer structure is a wrapper over a String type which is to be sanitized.



The Sanitize trait generalises types that are to be sanitized.