#[repr(transparent)]pub struct ExclusiveId {
pub id: Id,
/* private fields */
}Expand description
Represents an ID that can only be used by a single writer at a time.
ExclusiveIds are associated with one owning context (typically a thread) at a time.
Because they are Send and !Sync, they can be passed between contexts, but not used concurrently.
This makes use of Rust’s borrow checker to enforce a weaker form of software transactional memory (STM) without rollbacks - as these are not an issue with the heavy use of copy-on-write data structures.
They are automatically associated with the thread they are dropped from, which can be used in queries via the local_ids constraint.
You can also make use of explicit IdOwner containers to store them when not actively used in a transaction.
Most methods defined on ExclusiveId are low-level primitives meant to be used for the implementation of new ownership management strategies,
such as a transactional database that tracks checked out IDs for ownership, or distributed ledgers like blockchains.
Fields§
§id: IdThe underlying identifier.
Implementations§
Source§impl ExclusiveId
impl ExclusiveId
Sourcepub fn force(id: Id) -> Self
pub fn force(id: Id) -> Self
Forces a regular (read-only) Id to become a writable ExclusiveId.
This is a low-level primitive that is meant to be used for the implementation of new ownership management strategies, such as a transactional database that tracks checked out IDs for ownership, or distributed ledgers like blockchains.
This should be done with care, as it allows scenarios where multiple writers can create conflicting information for the same ID.
Similar caution should be applied when using the force_ref and forget methods.
§Arguments
id- TheIdto be forced into anExclusiveId.
Sourcepub fn force_ref(id: &Id) -> &Self
pub fn force_ref(id: &Id) -> &Self
Safely transmutes a reference to an Id into a reference to an ExclusiveId.
Similar caution should be applied when using the force method.
§Arguments
id- A reference to theIdto be transmuted.
Sourcepub fn forget(self) -> Id
pub fn forget(self) -> Id
Forgets the ExclusiveId, leaking ownership of the underlying Id, while returning it.
This is not as potentially problematic as force, because it prevents further writes with the ExclusiveId, thus avoiding potential conflicts.
§Returns
The underlying Id.
Methods from Deref<Target = Id>§
Sourcepub fn aquire(&self) -> Option<ExclusiveId>
pub fn aquire(&self) -> Option<ExclusiveId>
Takes ownership of this Id from the current write context (i.e. thread).
Returns None if this Id was not found, because it is not associated with this
write context, or because it is currently aquired.
Trait Implementations§
Source§impl AsRef<[u8]> for ExclusiveId
impl AsRef<[u8]> for ExclusiveId
Source§impl AsRef<ExclusiveId> for ExclusiveId
impl AsRef<ExclusiveId> for ExclusiveId
Source§fn as_ref(&self) -> &ExclusiveId
fn as_ref(&self) -> &ExclusiveId
Source§impl AsRef<ExclusiveId> for OwnedId<'_>
impl AsRef<ExclusiveId> for OwnedId<'_>
Source§fn as_ref(&self) -> &ExclusiveId
fn as_ref(&self) -> &ExclusiveId
Source§impl AsRef<Id> for ExclusiveId
impl AsRef<Id> for ExclusiveId
Source§impl Borrow<ExclusiveId> for OwnedId<'_>
impl Borrow<ExclusiveId> for OwnedId<'_>
Source§fn borrow(&self) -> &ExclusiveId
fn borrow(&self) -> &ExclusiveId
Source§impl Borrow<Id> for ExclusiveId
impl Borrow<Id> for ExclusiveId
Source§impl Debug for ExclusiveId
impl Debug for ExclusiveId
Source§impl Deref for ExclusiveId
impl Deref for ExclusiveId
Source§impl Display for ExclusiveId
impl Display for ExclusiveId
Source§impl Drop for ExclusiveId
impl Drop for ExclusiveId
Source§impl Ord for ExclusiveId
impl Ord for ExclusiveId
Source§fn cmp(&self, other: &ExclusiveId) -> Ordering
fn cmp(&self, other: &ExclusiveId) -> Ordering
1.21.0 · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl PartialEq for ExclusiveId
impl PartialEq for ExclusiveId
Source§impl PartialOrd for ExclusiveId
impl PartialOrd for ExclusiveId
Source§impl ToValue<GenId> for &ExclusiveId
impl ToValue<GenId> for &ExclusiveId
Source§impl ToValue<GenId> for ExclusiveId
impl ToValue<GenId> for ExclusiveId
Source§impl<'a> TryFromValue<'a, GenId> for ExclusiveId
impl<'a> TryFromValue<'a, GenId> for ExclusiveId
impl Eq for ExclusiveId
impl Send for ExclusiveId
impl StructuralPartialEq for ExclusiveId
Auto Trait Implementations§
impl Freeze for ExclusiveId
impl RefUnwindSafe for ExclusiveId
impl !Sync for ExclusiveId
impl Unpin for ExclusiveId
impl UnsafeUnpin for ExclusiveId
impl UnwindSafe for ExclusiveId
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
Source§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> ToHex for T
impl<T> ToHex for T
Source§fn encode_hex<U>(&self) -> Uwhere
U: FromIterator<char>,
fn encode_hex<U>(&self) -> Uwhere
U: FromIterator<char>,
self into the result. Lower case
letters are used (e.g. f9b4ca)Source§fn encode_hex_upper<U>(&self) -> Uwhere
U: FromIterator<char>,
fn encode_hex_upper<U>(&self) -> Uwhere
U: FromIterator<char>,
self into the result. Upper case
letters are used (e.g. F9B4CA)