pub struct StopRef<'a> { /* private fields */ }Expand description
A borrowed reference to a StopSource.
This is a lightweight reference that can only check for cancellation - it cannot trigger it. Use the source to cancel.
§Example
use almost_enough::{StopSource, Stop};
fn process(data: &[u8], stop: impl Stop) {
for (i, chunk) in data.chunks(100).enumerate() {
if i % 10 == 0 && stop.should_stop() {
return;
}
// process chunk...
}
}
let source = StopSource::new();
process(&[0u8; 1000], source.as_ref());§Copy Semantics
StopRef is Copy, so you can freely copy it without cloning:
use almost_enough::{StopSource, Stop};
let source = StopSource::new();
let r1 = source.as_ref();
let r2 = r1; // Copy
let r3 = r1; // Still valid
source.cancel();
assert!(r1.should_stop());
assert!(r2.should_stop());
assert!(r3.should_stop());Trait Implementations§
impl<'a> Copy for StopRef<'a>
Auto Trait Implementations§
impl<'a> Freeze for StopRef<'a>
impl<'a> RefUnwindSafe for StopRef<'a>
impl<'a> Send for StopRef<'a>
impl<'a> Sync for StopRef<'a>
impl<'a> Unpin for StopRef<'a>
impl<'a> UnwindSafe for StopRef<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> StopExt for Twhere
T: Stop,
impl<T> StopExt for Twhere
T: Stop,
Source§impl<T> TimeoutExt for Twhere
T: Stop,
impl<T> TimeoutExt for Twhere
T: Stop,
Source§fn with_timeout(self, duration: Duration) -> WithTimeout<Self>
fn with_timeout(self, duration: Duration) -> WithTimeout<Self>
Add a timeout to this stop. Read more
Source§fn with_deadline(self, deadline: Instant) -> WithTimeout<Self>
fn with_deadline(self, deadline: Instant) -> WithTimeout<Self>
Add an absolute deadline to this stop. Read more