From dd6c54db389697bb09546aec8bca0abd95f65a0b Mon Sep 17 00:00:00 2001 From: Nettika Date: Thu, 21 Jul 2022 12:29:32 -0700 Subject: [PATCH] Add documentation for built-in implementations and no_std --- readme.md | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/readme.md b/readme.md index acf443f..2aea9af 100644 --- a/readme.md +++ b/readme.md @@ -69,6 +69,56 @@ fn create_account(username: Valid) { } ``` +## Built-in implementations + +Implementations are provided for generic arrays `[T: Vet; N]` and the standard +library types `Vec` and `Option`. + +Arrays and `Vec`s are only valid if all of their individual elements are valid: + +```rust +let usernames = vec![ + Username("日向".to_string()), + Username("seán462".to_string()), + Username("lone wolf".to_string()) +].vet(); +// Invalid, whitespace in the third element + +let contact_numbers = [ + PhoneNumber("427-313-0255"), + PhoneNumber("+1 (708) 484-0523") +].vet(); +// Valid, all elements passed vetting +``` + +Options containing `None` are always valid: + +```rust +let mut email: Option = None; +email.vet(); // Valid + +let mut email: Option = Some("benjamin@@metanomial.com"); +email.vet(); // Invalid, regex test failed +``` + +## No-std support + +The default `std` feature flag can be disabled to use this library in no_std +contexts. Modify your dependency entry in `Cargo.toml` like so: + +```toml +[dependencies] +vet = { version = "0.1", default-features = false } +``` + +In no_std contexts with a memory allocator, implementations for `Vec` can be +reenabled with the `alloc` feature flag: + +```toml +[dependencies] +vet = { version = "0.1", default-features = false, features = ["alloc"] } +``` + ## License Licensed under either of