pub struct MemoryGuard<M: MemoryMetrics> {
pub(crate) state: GuardState<M>,
}Expand description
Guard representing a slice of reserved memory.
Fields§
§state: GuardState<M>Implementations§
Source§impl<M: MemoryMetrics> MemoryGuard<M>
impl<M: MemoryMetrics> MemoryGuard<M>
pub(crate) fn unlimited(quota: UnlimitedMemoryQuota<M>, bytes: u64) -> Self
pub(crate) fn limited( quota: MemoryQuota<M>, permit: OwnedSemaphorePermit, ) -> Self
Sourcepub fn granted_bytes(&self) -> u64
pub fn granted_bytes(&self) -> u64
Returns granted quota in bytes.
Sourcepub async fn acquire_additional(&mut self, bytes: u64) -> Result<()>
pub async fn acquire_additional(&mut self, bytes: u64) -> Result<()>
Acquires additional memory, waiting if necessary until enough is available.
On success, merges the new memory into this guard.
§Errors
- Returns error if requested bytes would exceed the manager’s total limit
- Returns error if the semaphore is unexpectedly closed
Sourcepub fn try_acquire_additional(&mut self, bytes: u64) -> bool
pub fn try_acquire_additional(&mut self, bytes: u64) -> bool
Tries to acquire additional memory without waiting.
On success, merges the new memory into this guard and returns true. On failure, returns false and leaves this guard unchanged.
Sourcepub async fn acquire_additional_with_policy(
&mut self,
bytes: u64,
policy: OnExhaustedPolicy,
) -> Result<()>
pub async fn acquire_additional_with_policy( &mut self, bytes: u64, policy: OnExhaustedPolicy, ) -> Result<()>
Acquires additional memory based on the given policy.
- For
OnExhaustedPolicy::Wait: Waits up to the timeout duration for memory to become available - For
OnExhaustedPolicy::Fail: Returns immediately if memory is not available
§Errors
MemoryLimitExceeded: Requested bytes would exceed the total limit (both policies), or memory is currently exhausted (Fail policy only)MemoryAcquireTimeout: Timeout elapsed while waiting for memory (Wait policy only)MemorySemaphoreClosed: The internal semaphore is unexpectedly closed (rare, indicates system issue)
Sourcepub fn release_partial(&mut self, bytes: u64) -> bool
pub fn release_partial(&mut self, bytes: u64) -> bool
Releases a portion of granted memory back to the pool before the guard is dropped.
Returns true if the release succeeds or is a no-op; false if the request exceeds granted.
Trait Implementations§
Source§impl<M: MemoryMetrics> Debug for MemoryGuard<M>
impl<M: MemoryMetrics> Debug for MemoryGuard<M>
Source§impl<M: MemoryMetrics> Drop for MemoryGuard<M>
impl<M: MemoryMetrics> Drop for MemoryGuard<M>
Auto Trait Implementations§
impl<M> Freeze for MemoryGuard<M>where
M: Freeze,
impl<M> !RefUnwindSafe for MemoryGuard<M>
impl<M> Send for MemoryGuard<M>
impl<M> Sync for MemoryGuard<M>
impl<M> Unpin for MemoryGuard<M>where
M: Unpin,
impl<M> UnsafeUnpin for MemoryGuard<M>where
M: UnsafeUnpin,
impl<M> !UnwindSafe for MemoryGuard<M>
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
Mutably borrows from an owned value. Read more
§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>
§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
Wrap the input message
T in a tonic::Request§impl<L> LayerExt<L> for L
impl<L> LayerExt<L> for L
§fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
Applies the layer to a service and wraps it in [
Layered].