pub struct ResourceLease<R: Send + 'static> { /* private fields */ }Expand description
An exclusive lease on a resource.
Dereferences to the resource itself. Dropping the lease returns the resource to the registry still live, so a lease
is a loan, never ownership. See ResourceRegistry for the full model.
This is the head lease. Dropping it relinquishes the holder’s claim, but doesn’t end the resource’s lease while
Subleases issued against it are still outstanding: the registry won’t hand the resource to another acquirer
until those come back too.
Implementations§
Source§impl<R: Send + 'static> ResourceLease<R>
impl<R: Send + 'static> ResourceLease<R>
Sourcepub fn kind(&self) -> ResourceKind
pub fn kind(&self) -> ResourceKind
Returns the kind of this resource.
Sourcepub fn key(&self) -> &MetaString
pub fn key(&self) -> &MetaString
Returns the key this resource is registered under, unique within its kind.
Sourcepub fn release(self)
pub fn release(self)
Returns the resource to the registry.
Equivalent to dropping the lease; useful where the return should be obvious at the call site.
Sourcepub fn discard(self)
pub fn discard(self)
Drops the resource instead of returning it, so the next acquisition creates a fresh one.
Use this when the resource has hit an error it can’t recover from and handing it to the next acquirer would pass the problem along.
Discarding doesn’t free the key any sooner than releasing would. Outstanding Subleases are what hold a
subdivided resource open, so the key stays reserved until they come back, and only then does the next
acquisition build a replacement – otherwise the replacement would exist alongside the thing being discarded.
Trait Implementations§
Source§impl<R: Send + 'static> Deref for ResourceLease<R>
impl<R: Send + 'static> Deref for ResourceLease<R>
Source§impl<R: Send + 'static> DerefMut for ResourceLease<R>
impl<R: Send + 'static> DerefMut for ResourceLease<R>
Auto Trait Implementations§
impl<R> Freeze for ResourceLease<R>where
R: Freeze,
impl<R> RefUnwindSafe for ResourceLease<R>where
R: RefUnwindSafe,
impl<R> Send for ResourceLease<R>
impl<R> Sync for ResourceLease<R>where
R: Sync,
impl<R> Unpin for ResourceLease<R>where
R: Unpin,
impl<R> UnwindSafe for ResourceLease<R>where
R: UnwindSafe,
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> 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> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::RequestSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<R> Rng for R
impl<R> Rng for R
Source§fn random<T>(&mut self) -> Twhere
StandardUniform: Distribution<T>,
fn random<T>(&mut self) -> Twhere
StandardUniform: Distribution<T>,
StandardUniform distribution. Read moreSource§fn random_iter<T>(self) -> Iter<StandardUniform, Self, T>
fn random_iter<T>(self) -> Iter<StandardUniform, Self, T>
Source§fn random_range<T, R>(&mut self, range: R) -> Twhere
T: SampleUniform,
R: SampleRange<T>,
fn random_range<T, R>(&mut self, range: R) -> Twhere
T: SampleUniform,
R: SampleRange<T>,
Source§fn random_bool(&mut self, p: f64) -> bool
fn random_bool(&mut self, p: f64) -> bool
p of being true. Read moreSource§fn random_ratio(&mut self, numerator: u32, denominator: u32) -> bool
fn random_ratio(&mut self, numerator: u32, denominator: u32) -> bool
numerator/denominator of being
true. Read moreSource§fn sample<T, D>(&mut self, distr: D) -> Twhere
D: Distribution<T>,
fn sample<T, D>(&mut self, distr: D) -> Twhere
D: Distribution<T>,
Source§fn sample_iter<T, D>(self, distr: D) -> Iter<D, Self, T>where
D: Distribution<T>,
Self: Sized,
fn sample_iter<T, D>(self, distr: D) -> Iter<D, Self, T>where
D: Distribution<T>,
Self: Sized,
Source§fn gen<T>(&mut self) -> Twhere
StandardUniform: Distribution<T>,
fn gen<T>(&mut self) -> Twhere
StandardUniform: Distribution<T>,
random to avoid conflict with the new gen keyword in Rust 2024.Rng::random.Source§fn gen_range<T, R>(&mut self, range: R) -> Twhere
T: SampleUniform,
R: SampleRange<T>,
fn gen_range<T, R>(&mut self, range: R) -> Twhere
T: SampleUniform,
R: SampleRange<T>,
random_rangeRng::random_range.§impl<T> Track for T
impl<T> Track for T
§fn track_resources(self, token: ResourceGroupToken) -> Tracked<Self>
fn track_resources(self, token: ResourceGroupToken) -> Tracked<Self>
Tracked wrapper. Read more§fn in_current_resource_group(self) -> Tracked<Self>
fn in_current_resource_group(self) -> Tracked<Self>
Tracked wrapper. Read moreSource§impl<R> TryRngCore for R
impl<R> TryRngCore for R
Source§type Error = Infallible
type Error = Infallible
Source§fn try_next_u32(&mut self) -> Result<u32, <R as TryRngCore>::Error>
fn try_next_u32(&mut self) -> Result<u32, <R as TryRngCore>::Error>
u32.Source§fn try_next_u64(&mut self) -> Result<u64, <R as TryRngCore>::Error>
fn try_next_u64(&mut self) -> Result<u64, <R as TryRngCore>::Error>
u64.Source§fn try_fill_bytes(
&mut self,
dst: &mut [u8],
) -> Result<(), <R as TryRngCore>::Error>
fn try_fill_bytes( &mut self, dst: &mut [u8], ) -> Result<(), <R as TryRngCore>::Error>
dest entirely with random data.Source§fn unwrap_mut(&mut self) -> UnwrapMut<'_, Self>
fn unwrap_mut(&mut self) -> UnwrapMut<'_, Self>
UnwrapMut wrapper.Source§fn read_adapter(&mut self) -> RngReadAdapter<'_, Self>where
Self: Sized,
fn read_adapter(&mut self) -> RngReadAdapter<'_, Self>where
Self: Sized,
RngCore to a RngReadAdapter.