1 unstable release
0.1.0 | Jun 23, 2022 |
---|
#2104 in Rust patterns
10KB
174 lines
Contains
The Contains crate has 2 traits Container and In.
Container
The Container trait can be used to abstract over
types that can contain items: Vec<T>
, &[T]
, HashMap<T>
, Option<T>
, ect.
use contains::Container;
let vec = vec![1, 2, 3, 4, 5];
let range = 0..5;
let option = Some(3);
let containers: &[&dyn Container<usize>] = &[&vec, &range, &option];
for container in containers {
assert!(container.does_contain(&3));
}
In
The In trait is the Inverse of the Container trait and represents a type that is in
a container. Mainly it reverse the call order by providing the is_in
method.
use contains::{Container, In};
let range = 0..5;
assert!(range.does_contain(&3)); // using does_contain
assert!(3.is_in(&range)); // using in
lib.rs
:
Contains
The Contains crate has 2 traits Container and In.
Container
The Container trait can be used to abstract over
types that can contain items: Vec<T>
, &[T]
, HashMap<T>
, Option<T>
, ect.
use contains::Container;
let vec = vec![1, 2, 3, 4, 5];
let range = 0..5;
let option = Some(3);
let containers: &[&dyn Container<usize>] = &[&vec, &range, &option];
for container in containers {
assert!(container.does_contain(&3));
}
In
The In trait is the Inverse of the Container trait and represents a type that is in
a container. Mainly it reverse the call order by providing the is_in
method.
use contains::{Container, In};
let range = 0..5;
assert!(range.does_contain(&3)); // using does_contain
assert!(3.is_in(&range)); // using in