strong 0.2.2

Strongly typed String
Documentation

STRONG   crates.io MIT

Rust is a statically and strongly typed systems programming language. We can create a new type wrapping primitives.

struct Age(i32);
struct Email(String);

There is a problem here, there are two types of strings in Rust, and it is hard to create strong types for both String and &str.

STRONG provides two types owned StrongBuf and unsized Strong.

use strong::{StrongBuf, Strong, Validator, validators::Email}

fn login(email: &Strong<Email>, password: &strong<Password>) { .. }

let email: StrongBuf<Email> = ..
let password: StrongBuf<Password> = ..
login(&email, password);

Email requires some_validators feature.

Getting Started

use strong::{StrongBuf, Strong, Validator, validators::Email}

enum Password {}
impl<T> Validator for Password {
    type Err = std::convert::Infallible;
}

let email: StrongBuf<Email> = StrongBuf::validate("foo".to_string());
let password: &Strong<Password> = Strong::validate("bar");

Shorthand

With shorthand feature, Str and S are exported and can be substituted for StrongBuf and Strong.

let email: StrongBuf<Email> = StrongBuf::validate("foo".to_string());
let email: Str<Email> = Str::validate("foo".to_string());

License

Licensed under MIT license (LICENSE-MIT or https://opensource.org/licenses/MIT)

Contributing

welcome!