Expand description
Provides a vector which content can be consumed
This allows multiple producers to add data to a shared data base. Any consumer
can take out data in a deleting manner if certain criteria are met, e.g. a search
pattern is fulfilled in a String
implementation.
This crate provides two different implementations:
The struct ConsumableVec
is a plain implementation of the trait Consumable
. Here the
user needs to take care of the ownership of the object when adding data or trying to consume
data from it.
The struct SharedConsumableVec
uses a ConsumableVec
which can be referenced by multiple owners
from multiple threads.
§Example:
use consumable_vec::{SharedConsumableVec, Consumable};
use std::thread;
let con_vec = SharedConsumableVec::default();
let producer = con_vec.clone();
thread::spawn(move || {
for n in 1..100 {
producer.add(format!("Produced: {}", n));
}
});
thread::spawn(move || {
loop {
if let Some(consumed) = con_vec.consume("Produced".to_string()) {
println!("{:?}", consumed);
if consumed.inner().iter().filter(|c| c.contains("99")).count() > 0 {
break;
}
}
}
});
Structs§
- Consumable
Vec - Generic structure for storing consumable data of type T
- Shared
Consumable Vec - Generic structure for storing consumable data of type T in a shared Vector
Traits§
- Consumable
- Consume content from a data collection