use core::marker::PhantomData;
use super::{ReadHandle, Stele};
use crate::sync::Arc;
use alloc::alloc::{Allocator, Global};
#[derive(Debug)]
pub struct WriteHandle<T, A: Allocator = Global> {
pub(crate) handle: Arc<Stele<T, A>>,
pub(crate) _unsync: PhantomData<*mut T>,
}
unsafe impl<T, A: Allocator> Send for WriteHandle<T, A> where T: Send + Sync {}
impl<T, A: Allocator> WriteHandle<T, A> {
pub fn push(&self, val: T) {
unsafe { self.handle.push(val) };
}
#[must_use]
pub fn new_read_handle(&self) -> ReadHandle<T, A> {
ReadHandle::from(&self.handle)
}
#[must_use]
pub fn read(&self, idx: usize) -> &T {
self.handle.read(idx)
}
#[must_use]
pub fn try_read(&self, idx: usize) -> Option<&T> {
self.handle.try_read(idx)
}
#[must_use]
pub fn len(&self) -> usize {
self.handle.len()
}
#[must_use]
pub fn is_empty(&self) -> bool {
self.handle.is_empty()
}
}
impl<T: Copy, A: Allocator> WriteHandle<T, A> {
#[must_use]
pub fn get(&self, idx: usize) -> T {
self.handle.get(idx)
}
}