Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .github/workflows/website.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
8 changes: 8 additions & 0 deletions book/src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]()
3 changes: 3 additions & 0 deletions book/src/validations/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Validations

- [Length](./length.md)
86 changes: 86 additions & 0 deletions book/src/validations/length.md
Original file line number Diff line number Diff line change
@@ -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
}
```
3 changes: 2 additions & 1 deletion packages/fortifier/src/validations/length.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -164,6 +164,7 @@ validate_with_len!(BTreeSet<T>, T);
validate_with_len!(BTreeMap<K, V>, K, V);
validate_with_len!(HashSet<T, S>, T, S);
validate_with_len!(HashMap<K, V, S>, K, V, S);
validate_with_len!(LinkedList<T>, T);
validate_with_len!(Vec<T>, T);
validate_with_len!(VecDeque<T>, T);
#[cfg(feature = "indexmap")]
Expand Down