Skip to main content

CachePolicy

Enum CachePolicy 

Source
pub enum CachePolicy<C, N> {
    Cacheable(C),
    NonCacheable(N),
}
Expand description

Result of a cache decision.

Represents whether an entity should be cached or passed through without caching. Both variants preserve the entity, just wrapped differently.

§Type Parameters

  • C - Type of the cacheable entity (usually the cached representation)
  • N - Type of the non-cacheable entity (usually the original response)

§Example

use hitbox_core::CachePolicy;

fn decide_caching(status: u16, body: String) -> CachePolicy<String, String> {
    if status == 200 {
        CachePolicy::Cacheable(body)
    } else {
        CachePolicy::NonCacheable(body)
    }
}

match decide_caching(200, "OK".to_string()) {
    CachePolicy::Cacheable(data) => println!("Cache: {}", data),
    CachePolicy::NonCacheable(data) => println!("Pass through: {}", data),
}

Variants§

§

Cacheable(C)

Entity should be cached.

§

NonCacheable(N)

Entity should not be cached; pass through directly.

Trait Implementations§

Source§

impl<C: Debug, N: Debug> Debug for CachePolicy<C, N>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<C, N> Freeze for CachePolicy<C, N>
where C: Freeze, N: Freeze,

§

impl<C, N> RefUnwindSafe for CachePolicy<C, N>

§

impl<C, N> Send for CachePolicy<C, N>
where C: Send, N: Send,

§

impl<C, N> Sync for CachePolicy<C, N>
where C: Sync, N: Sync,

§

impl<C, N> Unpin for CachePolicy<C, N>
where C: Unpin, N: Unpin,

§

impl<C, N> UnwindSafe for CachePolicy<C, N>
where C: UnwindSafe, N: UnwindSafe,

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>,

Source§

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>,

Source§

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.