diff --git a/.github/workflows/website.yml b/.github/workflows/website.yml index 3d4d507..6fbcc15 100644 --- a/.github/workflows/website.yml +++ b/.github/workflows/website.yml @@ -31,8 +31,11 @@ jobs: - name: Install mdBook run: cargo binstall --force -y mdbook mdbook-tabs + - name: Build Fortifier + run: cargo build -p fortifier + - name: Run tests - run: mdbook test + run: mdbook test -L ../target/debug/deps working-directory: book book-build: diff --git a/book/src/SUMMARY.md b/book/src/SUMMARY.md index 9399e12..03adf53 100644 --- a/book/src/SUMMARY.md +++ b/book/src/SUMMARY.md @@ -2,4 +2,12 @@ - [Introduction](./introduction.md) - [Getting Started](./getting-started.md) +- [Validations](./validations/README.md) + - [Email]() + - [Length](./validations/length.md) + - [Regex]() + - [URL]() +- [Integrations]() + - [Serde]() + - [Utoipa]() - [Contributing]() diff --git a/book/src/validations/README.md b/book/src/validations/README.md new file mode 100644 index 0000000..60505aa --- /dev/null +++ b/book/src/validations/README.md @@ -0,0 +1,3 @@ +# Validations + +- [Length](./length.md) diff --git a/book/src/validations/length.md b/book/src/validations/length.md new file mode 100644 index 0000000..a93deeb --- /dev/null +++ b/book/src/validations/length.md @@ -0,0 +1,86 @@ +# Length + +Validate the length of a string or iterable. + +```rust +# extern crate fortifier; +# use fortifier::Validate; +# +##[derive(Validate)] +struct User { + #[validate(length(min = 1, max = 256))] + name: String +} +``` + +## Types + +### String + +- [`str`](https://doc.rust-lang.org/std/primitive.str.html) +- [`String`](https://doc.rust-lang.org/std/string/struct.String.html) + +Validate the amount of characters ([`chars`](https://doc.rust-lang.org/std/primitive.str.html#method.chars)) in a string. + +### Iterable + +- [`[T]` (slice)](https://doc.rust-lang.org/std/primitive.slice.html) +- [`[T; N]` (array)](https://doc.rust-lang.org/std/primitive.array.html) +- [`BTreeSet`](https://doc.rust-lang.org/std/collections/struct.BTreeSet.html) +- [`BTreeMap`](https://doc.rust-lang.org/std/collections/struct.BTreeMap.html) +- [`HashSet`](https://doc.rust-lang.org/std/collections/struct.HashSet.html) +- [`HashMap`](https://doc.rust-lang.org/std/collections/struct.HashMap.html) +- [`IndexSet`](https://docs.rs/indexmap/latest/indexmap/set/struct.IndexSet.html) (requires feature `indexmap`) +- [`IndexMap`](https://docs.rs/indexmap/latest/indexmap/map/struct.IndexMap.html) (requires feature `indexmap`) +- [`LinkedList`](https://doc.rust-lang.org/std/collections/struct.LinkedList.html) +- [`Vec`](https://doc.rust-lang.org/std/vec/struct.Vec.html) +- [`VecDeque`](https://doc.rust-lang.org/std/collections/struct.VecDeque.html) + +Validate the amount of entries in an iterable. + +## Options + +### Equal + +The length should be equal to the specified expression. + +```rust +# extern crate fortifier; +# use fortifier::Validate; +# +##[derive(Validate)] +struct User { + #[validate(length(equal = 2))] + country_code: String +} +``` + +### Minimum + +The length should be equal to or greater than the specified expression. + +```rust +# extern crate fortifier; +# use fortifier::Validate; +# +##[derive(Validate)] +struct User { + #[validate(length(min = 1))] + name: String +} +``` + +### Maximum + +The length should be equal to or less than the specified expression. + +```rust +# extern crate fortifier; +# use fortifier::Validate; +# +##[derive(Validate)] +struct User { + #[validate(length(max = 256))] + name: String +} +``` diff --git a/packages/fortifier/src/validations/length.rs b/packages/fortifier/src/validations/length.rs index 36f8f23..17a3c01 100644 --- a/packages/fortifier/src/validations/length.rs +++ b/packages/fortifier/src/validations/length.rs @@ -1,7 +1,7 @@ use std::{ borrow::Cow, cell::{Ref, RefMut}, - collections::{BTreeMap, BTreeSet, HashMap, HashSet, VecDeque}, + collections::{BTreeMap, BTreeSet, HashMap, HashSet, LinkedList, VecDeque}, fmt::Display, rc::Rc, sync::Arc, @@ -164,6 +164,7 @@ validate_with_len!(BTreeSet, T); validate_with_len!(BTreeMap, K, V); validate_with_len!(HashSet, T, S); validate_with_len!(HashMap, K, V, S); +validate_with_len!(LinkedList, T); validate_with_len!(Vec, T); validate_with_len!(VecDeque, T); #[cfg(feature = "indexmap")]