Skip to main content

CacheKey

Trait CacheKey 

Source
pub trait CacheKey:
    Hash
    + Eq
    + Clone
    + Send
    + Sync
    + 'static {
    const BITS_COUNT: u32;
    const ZERO: Self;
    const ONE: Self;

    // Required methods
    fn from_usize(v: usize) -> Self;
    fn checked_mul(self, rhs: Self) -> Option<Self>;
    fn wrapping_add(self, rhs: Self) -> Self;
}
Expand description

Trait for cache key types used in flat-index computation.

Built-in implementations are provided for u64, u128, U256, U512, and U1024. For index spaces larger than 1024 bits, implement this trait for a wider integer type and use CachedFunction::with_key_type.

See module documentation for a complete custom key example.

Required Associated Constants§

Source

const BITS_COUNT: u32

Number of bits this key type can represent.

Source

const ZERO: Self

The zero value.

Source

const ONE: Self

The one value.

Required Methods§

Source

fn from_usize(v: usize) -> Self

Convert a usize to this key type.

Source

fn checked_mul(self, rhs: Self) -> Option<Self>

Checked multiplication. Returns None on overflow.

Source

fn wrapping_add(self, rhs: Self) -> Self

Wrapping addition (overflow wraps around).

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 CacheKey for u64

Source§

const BITS_COUNT: u32 = 64

Source§

const ZERO: Self = 0

Source§

const ONE: Self = 1

Source§

fn from_usize(v: usize) -> Self

Source§

fn checked_mul(self, rhs: Self) -> Option<Self>

Source§

fn wrapping_add(self, rhs: Self) -> Self

Source§

impl CacheKey for u128

Source§

const BITS_COUNT: u32 = 128

Source§

const ZERO: Self = 0

Source§

const ONE: Self = 1

Source§

fn from_usize(v: usize) -> Self

Source§

fn checked_mul(self, rhs: Self) -> Option<Self>

Source§

fn wrapping_add(self, rhs: Self) -> Self

Source§

impl CacheKey for U256

Source§

const BITS_COUNT: u32 = 256

Source§

const ZERO: Self = U256::ZERO

Source§

const ONE: Self = U256::ONE

Source§

fn from_usize(v: usize) -> Self

Source§

fn checked_mul(self, rhs: Self) -> Option<Self>

Source§

fn wrapping_add(self, rhs: Self) -> Self

Source§

impl CacheKey for U512

Source§

const BITS_COUNT: u32 = 512

Source§

const ZERO: Self = U512::ZERO

Source§

const ONE: Self = U512::ONE

Source§

fn from_usize(v: usize) -> Self

Source§

fn checked_mul(self, rhs: Self) -> Option<Self>

Source§

fn wrapping_add(self, rhs: Self) -> Self

Source§

impl CacheKey for U1024

Source§

const BITS_COUNT: u32 = 1024

Source§

const ZERO: Self = U1024::ZERO

Source§

const ONE: Self = U1024::ONE

Source§

fn from_usize(v: usize) -> Self

Source§

fn checked_mul(self, rhs: Self) -> Option<Self>

Source§

fn wrapping_add(self, rhs: Self) -> Self

Implementors§