Trait Container

Source
pub trait Container<T>: Deref<Target = T> + Value {
    // Required method
    fn into_inner(self) -> T;
}
Expand description

The trait defining the required functionality of container types

The Freedom API is generic over “containers”. Each implementer of the Api trait must also define a container. This is useful since certain clients will return Arc’d values, i.e. the caching client, while others return the values wrapped in a simple Inner type which is just a stack value.

However, for most cases this complexity can be ignored, since containers are required to implement Deref of T. So for read-only operations the container can be used as if it were T. For mutable access see Self::into_inner.

§Example

let request = client
    .get_request_by_id(42)
    .await?;

println!("Created on {}", request.created); // Direct access to created field
                                            // through the Container

Required Methods§

Source

fn into_inner(self) -> T

All containers are capable of returning the value they wrap

However, the runtime performance of this varies by client type. For crate::Client, this operation is essentially free, however for the caching client, this often results in a clone of the value.

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.

Implementations on Foreign Types§

Source§

impl<T: Deref<Target = T> + Value> Container<T> for Box<T>

Source§

fn into_inner(self) -> T

Implementors§

Source§

impl<T> Container<T> for Inner<T>
where T: Value,