custom-string 0.11.0-rc.2

This library aids in generating string types with custom validation.
Documentation

custom-string

Crates.io Docs.rs License: MIT

This library aids in generating string types with custom validation.

custom-string = "0.11.0-rc.2"

Features

serde

For more features see the Crate Docs.

Example

use custom_string::custom_string;

custom_string!(
    #[doc = "A lowercase string."],
    Lower,
    |s: &str| if !s.as_bytes().iter().all(|c| c.is_ascii_lowercase()) {
        Err("not lowercase")
    } else {
        Ok(())
    }
);

let owned: Lower = Lower::new("hello").unwrap();
assert_eq!(owned.value(), "hello");

let reference: LowerRef = owned.to_ref();
assert_eq!(reference.value(), "hello");

assert!(Lower::new("HELLO").is_err());