InstanceCopyOnWrite

Struct InstanceCopyOnWrite 

Source
pub struct InstanceCopyOnWrite<ITEM: Send + Debug> { /* private fields */ }
Expand description

A base instance which is used to perform CoW and non-CoW operations on the inner value.

Borrow:

let val = 
    InstanceCopyOnWrite::new(TestStruct::new(1, 2));
 
let test_borrow = val.borrow().unwrap();

CoW copy-on-write

let val = 
    InstanceCopyOnWrite::new(TestStruct::new(1, 2));
 
let test_borrow = val.borrow().unwrap();
let val = 
    InstanceCopyOnWrite::new(TestStruct::new(1, 2));
 
let mut transaction = val.start_copying().unwrap();
 
transaction.start = 5;
transaction.stop = 6;
 
transaction.completed(false).unwrap();

Exclusive lock (non-CoW)

let val = 
    InstanceCopyOnWrite::new(TestStruct::new(1, 2));
 
let lock = val.lock();
 
drop(lock);

Implementations§

Source§

impl<ITEM: Send + Debug> InstanceCopyOnWrite<ITEM>

Source

pub fn new(item: ITEM) -> Self

Cretaes new instance with the pre-initialized item.

Source

pub fn borrow(&self) -> Result<CowReadGuard<'_, ITEM>, CowGuardError>

Borrows the ITEM for read-only operations. The instance will remain unchaned even after the writing using copy-on-write. As long as the borrow exists, the exclusive lock is not possible.

§Returns

Either a Result::Ok with CowReadGuard or Result::Err with CowGuardError is returned.

Source

pub fn try_borrow(&self) -> Result<CowReadGuard<'_, ITEM>, CowGuardError>

Attempts to borrows the ITEM for read-only operations. If eclusive lock is pending, the error will be returned see CowReadGuard::new.

The instance will remain unchaned even after the writing using copy-on-write. As long as the borrow exists, the exclusive lock is not possible.

§Returns

Either a Result::Ok with CowReadGuard or Result::Err with CowGuardError is returned.

Source

pub fn lock(&self) -> Result<NoCowGuard<'_, ITEM>, NoCowGuardErr>

Makes the exclusive lock. See NoCowGuard for more information about pre-requests. See NoCowGuard::new for more info.

§Returns

Either a Result::Ok with NoCowGuard or Result::Err with NoCowGuardErr is returned.

Source

pub fn remove_poison_lock(&self) -> Result<NoCowGuard<'_, ITEM>, NoCowGuardErr>

Manually removes poison status by forcing the lock. (untested)

Does not check if any borrows.

See NoCowGuard for more info.

§Returns

Either a Result::Ok with NoCowGuard or Result::Err with NoCowGuardErr is returned.

Source

pub fn remove_poison_write(&self, new_inst: ITEM) -> Result<(), NoCowGuardErr>

Manually removes poison status by setting new_inst to the inner. (untested)

Is safer than Self::remove_poison_lock because active borrows would not be affected.

See NoCowGuard for more info.

§Returns

Either a Result::Ok with () or Result::Err with NoCowGuardErr is returned.

Source§

impl<ITEM: Send + Debug + Copy> InstanceCopyOnWrite<ITEM>

Source

pub fn start_copying( &self, ) -> Result<CowTransactionGuard<'_, ITEM>, CowGuardError>

Performing the copy-on-write by copying Copy the inner value ITEM.

See CowTransactionGuard for more info.

Either a Result::Ok with CowTransactionGuard or Result::Err with CowGuardError is returned.

Source

pub fn try_start_copying( &self, ) -> Result<CowTransactionGuard<'_, ITEM>, CowGuardError>

Attempts to perform the copy-on-write by copying Copy the inner value ITEM.

See CowTransactionGuard for more info.

Either a Result::Ok with CowTransactionGuard or Result::Err with CowGuardError is returned.

Source§

impl<ITEM: Send + Debug + Clone> InstanceCopyOnWrite<ITEM>

Source

pub fn start_cloning( &self, ) -> Result<CowTransactionGuard<'_, ITEM>, CowGuardError>

Performing the copy-on-write by cloning Clone the inner value ITEM.

See CowTransactionGuard for more info.

Either a Result::Ok with CowTransactionGuard or Result::Err with CowGuardError is returned.

Source

pub fn try_start_cloning( &self, ) -> Result<CowTransactionGuard<'_, ITEM>, CowGuardError>

Attempts to perform the copy-on-write by copying Clone the inner value ITEM.

See CowTransactionGuard for more info.

Either a Result::Ok with CowTransactionGuard or Result::Err with CowGuardError is returned.

Source§

impl<ITEM: Send + Debug + Default> InstanceCopyOnWrite<ITEM>

Source

pub fn start_default( &self, ) -> Result<CowTransactionGuard<'_, ITEM>, CowGuardError>

Performing the copy-on-write by creating the default Default of the inner value ITEM.

See CowTransactionGuard for more info.

Either a Result::Ok with CowTransactionGuard or Result::Err with CowGuardError is returned.

Source

pub fn try_start_default( &self, ) -> Result<CowTransactionGuard<'_, ITEM>, CowGuardError>

Attempts to perform the copy-on-write by creating the default Default of the inner value ITEM.

See CowTransactionGuard for more info.

Either a Result::Ok with CowTransactionGuard or Result::Err with CowGuardError is returned.

Source§

impl<ITEM: Send + Debug> InstanceCopyOnWrite<ITEM>

Source

pub fn start_new( &self, new_inst: ITEM, ) -> Result<CowTransactionGuard<'_, ITEM>, CowGuardError>

Performing the copy-on-write from the provided instance of the inner value ITEM.

See CowTransactionGuard for more info.

Either a Result::Ok with CowTransactionGuard or Result::Err with CowGuardError is returned.

Source

pub fn try_start_new( &self, new_inst: ITEM, ) -> Result<CowTransactionGuard<'_, ITEM>, CowGuardError>

Attempting to perform the copy-on-write from the provided instance of the inner value ITEM.

See CowTransactionGuard for more info.

Either a Result::Ok with CowTransactionGuard or Result::Err with CowGuardError is returned.

Trait Implementations§

Source§

impl<ITEM: Debug + Send + Debug> Debug for InstanceCopyOnWrite<ITEM>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<ITEM: Send + Debug> Drop for InstanceCopyOnWrite<ITEM>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<ITEM> !Freeze for InstanceCopyOnWrite<ITEM>

§

impl<ITEM> RefUnwindSafe for InstanceCopyOnWrite<ITEM>

§

impl<ITEM> Send for InstanceCopyOnWrite<ITEM>

§

impl<ITEM> Sync for InstanceCopyOnWrite<ITEM>

§

impl<ITEM> Unpin for InstanceCopyOnWrite<ITEM>

§

impl<ITEM> !UnwindSafe for InstanceCopyOnWrite<ITEM>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.