pub trait TryAsPooled<A>where
Self: Sized,{
type Error;
// Required methods
fn try_create(args: A) -> Result<Self, Self::Error>;
fn try_modify(&mut self, args: A) -> Result<(), Self::Error>;
}Expand description
Attempt to retrieve a pooled object from an ObjectPool, creating a new one if the
queue is empty.
The goal of this trait is to modify an existing object if available such that it is indistinguishable semantically from a newly created object, allowing user code to be agnostic of the provenance of the created object.
Required Associated Types§
Required Methods§
Sourcefn try_create(args: A) -> Result<Self, Self::Error>
fn try_create(args: A) -> Result<Self, Self::Error>
Create an instance of Self from the argument types.
Sourcefn try_modify(&mut self, args: A) -> Result<(), Self::Error>
fn try_modify(&mut self, args: A) -> Result<(), Self::Error>
Modify an existing object so it behaves semantically identical to an object
constructed using [try_create].
This is often trickier to achieve than first anticipated.
Note that it’s up to the user to decide what “semantically identical” means. For pooled objects like hash tables, the underlying capacity is not necessarily part of the identity of an object - but there are contexts where it matters.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.