|
| 1 | +# Length |
| 2 | + |
| 3 | +Validate the length of a string or iterable. |
| 4 | + |
| 5 | +```rust |
| 6 | +# extern crate fortifier; |
| 7 | +# use fortifier::Validate; |
| 8 | +# |
| 9 | +##[derive(Validate)] |
| 10 | +struct User { |
| 11 | + #[validate(length(min = 1, max = 256))] |
| 12 | + name: String |
| 13 | +} |
| 14 | +``` |
| 15 | + |
| 16 | +## Types |
| 17 | + |
| 18 | +### String |
| 19 | + |
| 20 | +- [`str`](https://doc.rust-lang.org/std/primitive.str.html) |
| 21 | +- [`String`](https://doc.rust-lang.org/std/string/struct.String.html) |
| 22 | + |
| 23 | +Validate the amount of characters ([`chars`](https://doc.rust-lang.org/std/primitive.str.html#method.chars)) in a string. |
| 24 | + |
| 25 | +### Iterable |
| 26 | + |
| 27 | +- [`[T]` (slice)](https://doc.rust-lang.org/std/primitive.slice.html) |
| 28 | +- [`[T; N]` (array)](https://doc.rust-lang.org/std/primitive.array.html) |
| 29 | +- [`BTreeSet`](https://doc.rust-lang.org/std/collections/struct.BTreeSet.html) |
| 30 | +- [`BTreeMap`](https://doc.rust-lang.org/std/collections/struct.BTreeMap.html) |
| 31 | +- [`HashSet`](https://doc.rust-lang.org/std/collections/struct.HashSet.html) |
| 32 | +- [`HashMap`](https://doc.rust-lang.org/std/collections/struct.HashMap.html) |
| 33 | +- [`IndexSet`](https://docs.rs/indexmap/latest/indexmap/set/struct.IndexSet.html) (requires feature `indexmap`) |
| 34 | +- [`IndexMap`](https://docs.rs/indexmap/latest/indexmap/map/struct.IndexMap.html) (requires feature `indexmap`) |
| 35 | +- [`LinkedList`](https://doc.rust-lang.org/std/collections/struct.LinkedList.html) |
| 36 | +- [`Vec`](https://doc.rust-lang.org/std/vec/struct.Vec.html) |
| 37 | +- [`VecDeque`](https://doc.rust-lang.org/std/collections/struct.VecDeque.html) |
| 38 | + |
| 39 | +Validate the amount of entries in an iterable. |
| 40 | + |
| 41 | +## Options |
| 42 | + |
| 43 | +### Equal |
| 44 | + |
| 45 | +The length should be equal to the specified expression. |
| 46 | + |
| 47 | +```rust |
| 48 | +# extern crate fortifier; |
| 49 | +# use fortifier::Validate; |
| 50 | +# |
| 51 | +##[derive(Validate)] |
| 52 | +struct User { |
| 53 | + #[validate(length(equal = 2))] |
| 54 | + country_code: String |
| 55 | +} |
| 56 | +``` |
| 57 | + |
| 58 | +### Minimum |
| 59 | + |
| 60 | +The length should be equal to or greater than the specified expression. |
| 61 | + |
| 62 | +```rust |
| 63 | +# extern crate fortifier; |
| 64 | +# use fortifier::Validate; |
| 65 | +# |
| 66 | +##[derive(Validate)] |
| 67 | +struct User { |
| 68 | + #[validate(length(min = 1))] |
| 69 | + name: String |
| 70 | +} |
| 71 | +``` |
| 72 | + |
| 73 | +### Maximum |
| 74 | + |
| 75 | +The length should be equal to or less than the specified expression. |
| 76 | + |
| 77 | +```rust |
| 78 | +# extern crate fortifier; |
| 79 | +# use fortifier::Validate; |
| 80 | +# |
| 81 | +##[derive(Validate)] |
| 82 | +struct User { |
| 83 | + #[validate(length(max = 256))] |
| 84 | + name: String |
| 85 | +} |
| 86 | +``` |
0 commit comments