pub(crate) enum IfEnabled<T> {
Enabled(T, EnabledToken),
Noop,
}Expand description
Either T, if we’re enabled, or nothing if we’re no-op
Used for runtime control of whether the memory quota is enabled:
we support explicitly creating a no-op tracker
with MemoryQuotaTracker::new_noop.
We use this rather than just Option because we also have data structures
(trackers, Accounts and so on)
which have been torn down, or are “dummy” or “dangling”,
which are supposed to return errors rather than no-op successes.
Variants§
Enabled(T, EnabledToken)
We’re enabled, and supposed to be tracking memory
The 2nd member causes this variant to prove that tracking is enabled.
If tracking is disabled at compile time, this variant is uninhabited
and the whole IfEnabled becomes a unit.
Noop
We’re inenabled and everything should be a lightweight no-op
Implementations§
Source§impl<T> IfEnabled<T>
impl<T> IfEnabled<T>
Sourcepub(crate) fn into_enabled(self) -> Option<T>
pub(crate) fn into_enabled(self) -> Option<T>
Convert to Option: return Some if this is Enabled
Sourcepub(crate) fn as_enabled(&self) -> Option<&T>
pub(crate) fn as_enabled(&self) -> Option<&T>
Take reference and convert to Option
Convenience helper equivalent to .as_ref().into_enabled().
Sourcepub(crate) fn enabled_or_bug(self) -> Result<T, Bug>
pub(crate) fn enabled_or_bug(self) -> Result<T, Bug>
Return the contents of the Enabled, or declare it a Bug
Trait Implementations§
Source§impl<T: PartialEq> PartialEq for IfEnabled<T>
impl<T: PartialEq> PartialEq for IfEnabled<T>
impl<T: Eq> Eq for IfEnabled<T>
impl<T> StructuralPartialEq for IfEnabled<T>
Auto Trait Implementations§
impl<T> Freeze for IfEnabled<T>where
T: Freeze,
impl<T> RefUnwindSafe for IfEnabled<T>where
T: RefUnwindSafe,
impl<T> Send for IfEnabled<T>where
T: Send,
impl<T> Sync for IfEnabled<T>where
T: Sync,
impl<T> Unpin for IfEnabled<T>where
T: Unpin,
impl<T> UnsafeUnpin for IfEnabled<T>where
T: UnsafeUnpin,
impl<T> UnwindSafe for IfEnabled<T>where
T: UnwindSafe,
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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<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> 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 more