pub struct TypedParticipation<T> { /* private fields */ }
Expand description
A Participation
for use only for tracking the memory use of objects of type T
Wrapping a Participation
in a TypedParticipation
helps prevent accidentally passing wrongly calculated costs
to claim
and release
.
Implementations§
Source§impl<T> TypedParticipation<T>
impl<T> TypedParticipation<T>
Sourcepub fn new(raw: Participation) -> Self
pub fn new(raw: Participation) -> Self
Wrap a Participation
, ensuring that future calls claim and release only T
Sourcepub fn claim(&mut self, t: &impl HasTypedMemoryCost<T>) -> Result<(), Error>
pub fn claim(&mut self, t: &impl HasTypedMemoryCost<T>) -> Result<(), Error>
Record increase in memory use, of a T: HasMemoryCost
or a TypedMemoryCost<T>
Sourcepub fn release(&mut self, t: &impl HasTypedMemoryCost<T>)
pub fn release(&mut self, t: &impl HasTypedMemoryCost<T>)
Record decrease in memory use, of a T: HasMemoryCost
or a TypedMemoryCost<T>
Sourcepub fn try_claim<C, F, E, R>(
&mut self,
item: C,
call: F,
) -> Result<Result<R, E>, Error>
pub fn try_claim<C, F, E, R>( &mut self, item: C, call: F, ) -> Result<Result<R, E>, Error>
Claiming wrapper for a closure
Claims the memory, iff call
succeeds.
Specifically:
Claims memory for item
. If that fails, returns the error.
If the claim succeeded, calls call
.
If it fails or panics, the memory is released, undoing the claim,
and the error is returned (or the panic propagated).
In these error cases, item
will typically be dropped by call
,
it is not convenient for call
to do otherwise.
If that’s wanted, use try_claim_or_return
.
Sourcepub fn try_claim_or_return<C, F, E, R>(
&mut self,
item: C,
call: F,
) -> Result<Result<R, E>, (Error, C)>
pub fn try_claim_or_return<C, F, E, R>( &mut self, item: C, call: F, ) -> Result<Result<R, E>, (Error, C)>
Claiming wrapper for a closure
Claims the memory, iff call
succeeds.
Like try_claim
,
but returns the item if memory claim fails.
Typically, a failing call
will need to return the item in E
.
Sourcepub fn as_raw(&mut self) -> &mut Participation
pub fn as_raw(&mut self) -> &mut Participation
Mutably access the inner Participation
This bypasses the type check.
It is up to you to make sure that the claim
and release
calls
are only made with properly calculated costs.
Sourcepub fn into_raw(self) -> Participation
pub fn into_raw(self) -> Participation
Unwrap, and obtain the inner Participation
Methods from Deref<Target = Participation>§
Sourcepub fn account(&self) -> WeakAccount
pub fn account(&self) -> WeakAccount
Obtain a handle onto the account
The returned handle is weak, and needs to be upgraded before use,
since a Participation
doesn’t keep its Account alive.
The returned WeakAccount
is equivalent to
all the other account handles for the same account.
Trait Implementations§
Source§impl<T> Clone for TypedParticipation<T>
impl<T> Clone for TypedParticipation<T>
Source§impl<T> Debug for TypedParticipation<T>
impl<T> Debug for TypedParticipation<T>
Source§impl<T> Deref for TypedParticipation<T>
impl<T> Deref for TypedParticipation<T>
Source§impl<T> From<Participation> for TypedParticipation<T>
impl<T> From<Participation> for TypedParticipation<T>
Source§fn from(untyped: Participation) -> TypedParticipation<T>
fn from(untyped: Participation) -> TypedParticipation<T>
Auto Trait Implementations§
impl<T> Freeze for TypedParticipation<T>
impl<T> RefUnwindSafe for TypedParticipation<T>
impl<T> Send for TypedParticipation<T>
impl<T> Sync for TypedParticipation<T>
impl<T> Unpin for TypedParticipation<T>
impl<T> UnwindSafe for TypedParticipation<T>
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<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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> Pointable for T
impl<T> Pointable for T
Source§impl<T> WithSubscriber for T
impl<T> WithSubscriber for T
Source§fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
Source§fn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
impl<T> ErasedDestructor for Twhere
T: 'static,
Layout§
Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...)
attributes. Please see the Rust Reference's “Type Layout” chapter for details on type layout guarantees.
Size: 32 bytes