iron_valid 0.4.1

Request validation library for iron, based on Laravel's validation
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
use params::{Map, Value};

pub fn validate_distinct(values: &Map, field: &str) -> Result<Option<Value>, String> {
    match values.find(&[field]) {
        Some(&Value::Array(ref value)) => {
            let mut checked: Vec<Value> = Vec::with_capacity(value.len());
            for item in value {
                if checked.contains(item) {
                    return Err(format!("The {} field must not contain any duplicate values.",
                                       field));
                }
                checked.push(item.clone());
            }
            Ok(None)
        }
        _ => Ok(None),
    }
}