contains

Crates.iocontains
lib.rscontains
version0.1.0
sourcesrc
created_at2022-06-23 23:49:35.589197
updated_at2022-06-23 23:49:35.589197
descriptionA Container trait
homepage
repositoryhttps://github.com/Jon-Davis/contains
max_upload_size
id612127
size10,438
Jonathon Davis (Jon-Davis)

documentation

https://docs.rs/container

README

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
Commit count: 4

cargo fmt