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>
impl<ITEM: Send + Debug> InstanceCopyOnWrite<ITEM>
Sourcepub fn borrow(&self) -> Result<CowReadGuard<'_, ITEM>, CowGuardError>
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.
Sourcepub fn try_borrow(&self) -> Result<CowReadGuard<'_, ITEM>, CowGuardError>
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.
Sourcepub fn lock(&self) -> Result<NoCowGuard<'_, ITEM>, NoCowGuardErr>
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.
Sourcepub fn remove_poison_lock(&self) -> Result<NoCowGuard<'_, ITEM>, NoCowGuardErr>
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.
Sourcepub fn remove_poison_write(&self, new_inst: ITEM) -> Result<(), NoCowGuardErr>
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.
-
NoCowGuardErr::AlreadyLocked - if someone is already attempting to depoison.
-
NoCowGuardErr::Poisoned - depoisoning have failed
Source§impl<ITEM: Send + Debug + Copy> InstanceCopyOnWrite<ITEM>
impl<ITEM: Send + Debug + Copy> InstanceCopyOnWrite<ITEM>
Sourcepub fn start_copying(
&self,
) -> Result<CowTransactionGuard<'_, ITEM>, CowGuardError>
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.
Sourcepub fn try_start_copying(
&self,
) -> Result<CowTransactionGuard<'_, ITEM>, CowGuardError>
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>
impl<ITEM: Send + Debug + Clone> InstanceCopyOnWrite<ITEM>
Sourcepub fn start_cloning(
&self,
) -> Result<CowTransactionGuard<'_, ITEM>, CowGuardError>
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.
Sourcepub fn try_start_cloning(
&self,
) -> Result<CowTransactionGuard<'_, ITEM>, CowGuardError>
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>
impl<ITEM: Send + Debug + Default> InstanceCopyOnWrite<ITEM>
Sourcepub fn start_default(
&self,
) -> Result<CowTransactionGuard<'_, ITEM>, CowGuardError>
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.
Sourcepub fn try_start_default(
&self,
) -> Result<CowTransactionGuard<'_, ITEM>, CowGuardError>
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>
impl<ITEM: Send + Debug> InstanceCopyOnWrite<ITEM>
Sourcepub fn start_new(
&self,
new_inst: ITEM,
) -> Result<CowTransactionGuard<'_, ITEM>, CowGuardError>
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.
Sourcepub fn try_start_new(
&self,
new_inst: ITEM,
) -> Result<CowTransactionGuard<'_, ITEM>, CowGuardError>
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.