Struct trillium_http::StateSet

source ·
pub struct StateSet(/* private fields */);
Expand description

Store and retrieve values by TypeId. This allows storing arbitrary data that implements Sync + Send + 'static.

Implementations§

source§

impl StateSet

source

pub fn new() -> Self

Create an empty StateSet.

source

pub fn insert<T: Send + Sync + 'static>(&mut self, val: T) -> Option<T>

Insert a value into this StateSet.

If a value of this type already exists, it will be returned.

source

pub fn contains<T: 'static>(&self) -> bool

Check if container contains value for type

source

pub fn get<T: 'static>(&self) -> Option<&T>

Get a reference to a value previously inserted on this StateSet.

source

pub fn get_mut<T: 'static>(&mut self) -> Option<&mut T>

Get a mutable reference to a value previously inserted on this StateSet.

source

pub fn take<T: 'static>(&mut self) -> Option<T>

Remove a value from this StateSet.

If a value of this type exists, it will be returned.

source

pub fn get_or_insert<T: Send + Sync + 'static>(&mut self, default: T) -> &mut T

Gets a value from this StateSet or populates it with the provided default.

source

pub fn get_or_insert_with<F, T>(&mut self, default: F) -> &mut T
where F: FnOnce() -> T, T: Send + Sync + 'static,

Gets a value from this StateSet or populates it with the provided default function.

Trait Implementations§

source§

impl Debug for StateSet

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for StateSet

source§

fn default() -> StateSet

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.