iron_valid 0.5.0

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_array(values: &Map, field: &[&str]) -> Result<Option<Value>, String> {
    match values.find(field) {
        Some(&Value::Array(_)) => Ok(None),
        None => {
            // Allow empty values
            Ok(None)
        }
        _ => {
            Err(format!("The {} field must be an array.",
                        field.last()
                            .unwrap()
                            .to_lowercase()
                            .replace("_", " ")))
        }
    }
}