1 unstable release

new 0.1.0 Jan 15, 2025

#691 in Procedural macros


Used in seventy

Apache-2.0

19KB
247 lines

Seventy

Rust newtype sanitization & validation

Overview

Seventy is a simple newtype sanitizer and validator.

There is no error handling. If you need to know why the newtype couldn't be created, this crate isn't for you.

Usage

use seventy::{
    builtins::{compare::*, string::*},
    seventy, Newtype,
};

#[seventy(
    sanitize(trim),
    validate(alphanumeric, length::chars(within(5..=20))),
)]
pub struct Username(String);

assert_eq!(
    Username::try_new("   username   ").unwrap().into_inner(),
    "username"
);

assert!(Username::try_new("   u$ername   ").is_err());

lib.rs:

Procedural macros for Seventy.

Dependencies

~210–650KB
~15K SLoC