#[cfg(any(feature = "async", doc))]
use crate::AsyncHeapRB;
use crate::LocalHeapRB;
use crate::SharedHeapRB;
#[allow(unused_imports)]
use crate::iterators::ProdIter;
#[cfg(any(feature = "async", doc))]
use crate::iters_components::AsyncComp;
#[cfg(any(feature = "async", doc))]
use crate::iters_components::AsyncCompMut;
use crate::iters_components::LocalComp;
use crate::iters_components::LocalCompMut;
use crate::iters_components::SharedComp;
use crate::iters_components::SharedCompMut;
#[cfg(any(feature = "async", doc))]
use crate::ring_buffer::types::AsyncHeapRBMut;
use crate::ring_buffer::types::LocalHeapRBMut;
use crate::ring_buffer::types::SharedHeapRBMut;
use crate::storage_components::HeapStorage;
use crate::utils::UnsafeSyncCell;
use alloc::boxed::Box;
use alloc::vec;
use alloc::vec::Vec;
macro_rules! impl_rb {
($t: tt, $i: tt) => {
impl<T> From<Vec<T>> for $t<T> {
#[doc = concat!("Converts a `Vec<T>` into a [`", stringify!($t), "`].")]
fn from(value: Vec<T>) -> Self {
assert!(value.len() > 0);
Self::_from(HeapStorage::from(value), $i::default())
}
}
impl<T> $t<T> {
#[doc = concat!("Creates a new [`", stringify!($t), "`] with given capacity and zeroed (uninitialised) elements.")]
pub unsafe fn new_zeroed(capacity: usize) -> Self {
assert!(capacity > 0);
Self::_from(
HeapStorage::from(
(0..capacity)
.map(|_| UnsafeSyncCell::new_zeroed()).collect::<Box<[UnsafeSyncCell<T>]>>()
),
$i::default()
)
}
#[doc = concat!("Creates a new [`", stringify!($t), "`] with given capacity and elements initialised to `default`.")]
pub fn default(capacity: usize) -> Self
where T: Default + Clone {
assert!(capacity > 0);
Self::from(vec![T::default(); capacity])
}
}
};
}
#[cfg(any(feature = "async", doc))]
impl_rb!(AsyncHeapRB, AsyncComp);
#[cfg(any(feature = "async", doc))]
impl_rb!(AsyncHeapRBMut, AsyncCompMut);
impl_rb!(SharedHeapRB, SharedComp);
impl_rb!(SharedHeapRBMut, SharedCompMut);
impl_rb!(LocalHeapRB, LocalComp);
impl_rb!(LocalHeapRBMut, LocalCompMut);