#![warn(
missing_docs,
rust_2018_idioms,
missing_debug_implementations,
intra_doc_link_resolution_failure
)]
#![allow(clippy::type_complexity)]
use one_way_slot_map::{SlotMap, SlotMapKey as Key, SlotMapKeyData};
use std::sync::{atomic, Arc, Mutex};
mod inner;
use crate::inner::Inner;
use evmap::ShallowCopy;
use slab::Slab;
pub(crate) type Epochs = Arc<Mutex<Slab<Arc<atomic::AtomicUsize>>>>;
#[non_exhaustive]
#[derive(PartialEq, Eq, Debug)]
pub(crate) enum Operation<V> {
NoOp,
Replace(SlotMapKeyData, V),
Add(V),
Remove(SlotMapKeyData),
Clear,
}
mod write;
pub use crate::write::WriteHandle;
mod read;
pub use crate::read::{MapReadRef, ReadGuard, ReadHandle, ReadHandleFactory};
pub fn new<K, P, V>() -> (ReadHandle<K, P, V>, WriteHandle<K, P, V>)
where
K: Key<P>,
V: ShallowCopy,
{
let epochs = Default::default();
let inner = Inner::new();
let mut w_handle = Inner::new();
w_handle.mark_ready();
let r = read::new(inner, Arc::clone(&epochs));
let w = write::new(w_handle, epochs, r.clone());
(r, w)
}
pub fn new_with_data<K, P, V>(
data: SlotMap<K, P, V>,
) -> (ReadHandle<K, P, V>, WriteHandle<K, P, V>)
where
K: Key<P>,
V: ShallowCopy,
{
let epochs = Default::default();
let (inner_r, inner_w) = Inner::new_with_data(data);
let r = read::new(inner_r, Arc::clone(&epochs));
let w = write::new(inner_w, epochs, r.clone());
(r, w)
}