pub struct Account(/* private fields */);
Expand description
Handle onto an Account
An Account
is a handle. All clones refer to the same underlying conceptual Account.
Account
s are created using MemoryQuotaTracker::new_account
.
§Use in Arti
In Arti, we usually use a newtype around Account
, rather than a bare Account
.
See tor_proto::memquota
.
Implementations§
Source§impl Account
impl Account
Sourcepub fn register_participant(
&self,
particip: Weak<dyn IsParticipant>,
) -> Result<Participation, Error>
pub fn register_participant( &self, particip: Weak<dyn IsParticipant>, ) -> Result<Participation, Error>
Register a new Participant
Returns the Participation
, which can be used to record memory allocations.
Often, your implementation of IsParticipant
wants to contain the Participation
.
If so, use register_participant_with
instead.
Sourcepub fn register_participant_with<P: IsParticipant, X, E>(
&self,
now: CoarseInstant,
constructor: impl FnOnce(Participation) -> Result<(Arc<P>, X), E>,
) -> Result<Result<(Arc<P>, X), E>, Error>
pub fn register_participant_with<P: IsParticipant, X, E>( &self, now: CoarseInstant, constructor: impl FnOnce(Participation) -> Result<(Arc<P>, X), E>, ) -> Result<Result<(Arc<P>, X), E>, Error>
Register a new Participant using a constructor
Passes constructor
a Participation
for the nascent Participant.
Returns the P: IsParticipant
provided by the constructor.
For use when your impl
IsParticipant
wants to own the Participation
.
§Re-entrancy guarantees
The Participation
may be used by constructor
for claiming memory use,
even during construction.
constructor
may also clone the Participation
, etc.
Reclamation callbacks (via the P as IsParticipant
impl) cannot occur
until constructor
returns.
§Error handling
Failures can occur before constructor
is called,
or be detected afterwards.
If a failure is detected after constructor
returns,
the Arc<P>
from constructor
will be dropped
(resulting in P
being dropped, unless constructor
kept another clone of it).
constructor
may also fail (throwing a different error type, E
),
in which case register_participant_with
returns Ok(Err(E))
.
On successful setup of the Participant, returns Ok(Ok(Arc<P>))
.
Sourcepub fn new_child(&self) -> Result<Self>
pub fn new_child(&self) -> Result<Self>
Obtain a new Account
which is a child of this one
Equivalent to
MemoryQuotaTracker.new_account
(Some(..))
Sourcepub fn tracker(&self) -> Arc<MemoryQuotaTracker>
pub fn tracker(&self) -> Arc<MemoryQuotaTracker>
Obtains a handle for the MemoryQuotaTracker
Sourcepub fn downgrade(&self) -> WeakAccount
pub fn downgrade(&self) -> WeakAccount
Downgrade to a weak handle for the same Account
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Account
impl RefUnwindSafe for Account
impl Send for Account
impl Sync for Account
impl Unpin for Account
impl UnwindSafe for Account
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,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§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 more