pub struct PinTokenLock<T: ?Sized, Keyhole> { /* private fields */ }Expand description
A pinned mutual exclusive primitive that can be accessed using a
Token<Keyhole> with a very low overhead.
Unlike the unpinned variant TokenLock, PinTokenLock does not expose
&mut T unless the receiver type is &mut Self. This way, the pinning
invariants are maintained.
See the module-level documentation for more details.
§Examples
use std::{pin::Pin, sync::Arc};
use tokenlock::{ArcToken, PinTokenLock};
let mut token = ArcToken::new();
let mut value = 0;
let future = Arc::pin(PinTokenLock::new(token.id(), async { value = 42; }));
// Use `token` to get `Pin<&mut impl Future>`
futures::executor::block_on(Pin::as_ref(&future).write_pin(&mut token));
drop(future);
assert_eq!(value, 42);Implementations§
Source§impl<T, Keyhole> PinTokenLock<T, Keyhole>
§Construction and Destruction
impl<T, Keyhole> PinTokenLock<T, Keyhole>
§Construction and Destruction
Source§impl<T: ?Sized, Keyhole> PinTokenLock<T, Keyhole>
§Miscellaneous
impl<T: ?Sized, Keyhole> PinTokenLock<T, Keyhole>
§Miscellaneous
Source§impl<T: ?Sized, Keyhole> PinTokenLock<T, Keyhole>
§Borrowing
impl<T: ?Sized, Keyhole> PinTokenLock<T, Keyhole>
§Borrowing
Sourcepub fn read<'a, K: Token<Keyhole>>(&'a self, token: &'a K) -> &'a T
pub fn read<'a, K: Token<Keyhole>>(&'a self, token: &'a K) -> &'a T
Get a reference to the contained data. Panic if token doesn’t fit in
the keyhole.
Sourcepub fn read_pin<'a, K: Token<Keyhole>>(
self: Pin<&'a Self>,
token: &'a K,
) -> Pin<&'a T>
pub fn read_pin<'a, K: Token<Keyhole>>( self: Pin<&'a Self>, token: &'a K, ) -> Pin<&'a T>
Get a pinned reference to the contained data. Panic if token doesn’t fit in
the keyhole.
Sourcepub fn write_pin<'a, K: Token<Keyhole>>(
self: Pin<&'a Self>,
token: &'a mut K,
) -> Pin<&'a mut T>
pub fn write_pin<'a, K: Token<Keyhole>>( self: Pin<&'a Self>, token: &'a mut K, ) -> Pin<&'a mut T>
Get a mutable pinned reference to the contained data. Panic if token doesn’t
fit in the keyhole.
Sourcepub fn try_read<'a, K: Token<Keyhole>>(
&'a self,
token: &'a K,
) -> Result<&'a T, BadTokenError>
pub fn try_read<'a, K: Token<Keyhole>>( &'a self, token: &'a K, ) -> Result<&'a T, BadTokenError>
Get a reference to the contained data. Return BadTokenError if token
doesn’t fit in the keyhole.
Sourcepub fn try_read_pin<'a, K: Token<Keyhole>>(
self: Pin<&'a Self>,
token: &'a K,
) -> Result<Pin<&'a T>, BadTokenError>
pub fn try_read_pin<'a, K: Token<Keyhole>>( self: Pin<&'a Self>, token: &'a K, ) -> Result<Pin<&'a T>, BadTokenError>
Get a pinned reference to the contained data. Return BadTokenError if token
doesn’t fit in the keyhole.
Sourcepub fn try_write_pin<'a, K: Token<Keyhole>>(
self: Pin<&'a Self>,
token: &'a mut K,
) -> Result<Pin<&'a mut T>, BadTokenError>
pub fn try_write_pin<'a, K: Token<Keyhole>>( self: Pin<&'a Self>, token: &'a mut K, ) -> Result<Pin<&'a mut T>, BadTokenError>
Get a mutable pinned reference to the contained data. Return BadTokenError if
token doesn’t fit in the keyhole.
Sourcepub fn get_pin_mut(self: Pin<&mut Self>) -> Pin<&mut T>
pub fn get_pin_mut(self: Pin<&mut Self>) -> Pin<&mut T>
Get a mutable pinned reference to the contained data.
Source§impl<T, Keyhole> PinTokenLock<T, Keyhole>
§Utilities
impl<T, Keyhole> PinTokenLock<T, Keyhole>
§Utilities
Sourcepub fn get<K: Token<Keyhole>>(&self, token: &K) -> Twhere
T: Clone,
pub fn get<K: Token<Keyhole>>(&self, token: &K) -> Twhere
T: Clone,
Get the contained data by cloning. Panic if token doesn’t fit in
the keyhole.
Sourcepub fn try_get<K: Token<Keyhole>>(&self, token: &K) -> Result<T, BadTokenError>where
T: Clone,
pub fn try_get<K: Token<Keyhole>>(&self, token: &K) -> Result<T, BadTokenError>where
T: Clone,
Get the contained data by cloning. Return BadTokenError if token
doesn’t fit in the keyhole.