Crates.io | contains |
lib.rs | contains |
version | 0.1.0 |
source | src |
created_at | 2022-06-23 23:49:35.589197 |
updated_at | 2022-06-23 23:49:35.589197 |
description | A Container trait |
homepage | |
repository | https://github.com/Jon-Davis/contains |
max_upload_size | |
id | 612127 |
size | 10,438 |
The Contains crate has 2 traits Container and In.
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));
}
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