Skip to content

Commit

Permalink
Remove read methods from HzrdWriter
Browse files Browse the repository at this point in the history
  • Loading branch information
skogseth committed Sep 27, 2023
1 parent faaa908 commit 0882aeb
Showing 1 changed file with 2 additions and 51 deletions.
53 changes: 2 additions & 51 deletions src/pair.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,27 +37,13 @@ For in-depth guide see the [module-level documentation](crate::pair).
pub struct HzrdWriter<T> {
core: Box<HzrdCore<T>>,
ptrs: NonNull<Ptrs<T>>,
hzrd_ptr: NonNull<HzrdPtr>,
}

struct Ptrs<T> {
hzrd: HzrdPtrs,
retired: RetiredPtrs<T>,
}

unsafe impl<T> crate::core::Read for HzrdWriter<T> {
type T = T;

unsafe fn core(&self) -> &HzrdCore<Self::T> {
&self.core
}

unsafe fn hzrd_ptr(&self) -> &HzrdPtr {
// SAFETY: This pointer is valid for as long as this cell is
unsafe { self.hzrd_ptr.as_ref() }
}
}

impl<T> HzrdWriter<T> {
/**
Construct a new [`HzrdWriter`] containing the given value.
Expand All @@ -69,7 +55,7 @@ impl<T> HzrdWriter<T> {
#
let writer = HzrdWriter::new(0);
#
# assert_eq!(writer.get(), 0);
# assert_eq!(writer.new_reader().get(), 0);
```
*/
pub fn new(value: T) -> Self {
Expand Down Expand Up @@ -127,53 +113,18 @@ impl<T> HzrdWriter<T> {
ptrs.retired.add(RetiredPtr::new(old_ptr));
ptrs.retired.reclaim(&ptrs.hzrd);
}

/**
Get a handle holding a reference to the current value of the container
See [`HzrdCell::read`] for a more detailed description
*/
pub fn read(&mut self) -> RefHandle<T> {
<Self as crate::core::Read>::read(self)
}

/// Get the value of the container (requires the type to be [`Copy`])
pub fn get(&self) -> T
where
T: Copy,
{
<Self as crate::core::Read>::get(self)
}

/// Read the contained value and clone it (requires type to be [`Clone`])
pub fn cloned(&self) -> T
where
T: Clone,
{
<Self as crate::core::Read>::cloned(self)
}

/// Read the contained value and map it
///
/// See [`HzrdCell::read_and_map`] for a more detailed description
pub fn read_and_map<U, F: FnOnce(&T) -> U>(&self, f: F) -> U {
<Self as crate::core::Read>::read_and_map(self, f)
}
}

impl<T> From<Box<T>> for HzrdWriter<T> {
fn from(boxed: Box<T>) -> Self {
let mut ptrs = Ptrs {
let ptrs = Ptrs {
hzrd: HzrdPtrs::new(),
retired: RetiredPtrs::new(),
};

let hzrd_ptr = ptrs.hzrd.get();

Self {
core: Box::new(HzrdCore::new(boxed)),
ptrs: crate::utils::allocate(ptrs),
hzrd_ptr,
}
}
}
Expand Down

0 comments on commit 0882aeb

Please sign in to comment.