Skip to main content

CacheKey

Trait CacheKey 

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§

const BITS_COUNT: u32

Number of bits this key type can represent.

const ZERO: Self

The zero value.

const ONE: Self

The one value.

Required Methods§

fn from_usize(v: usize) -> Self

Convert a usize to this key type.

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

Checked multiplication. Returns None on overflow.

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§

§

impl CacheKey for u64

§

const BITS_COUNT: u32 = 64

§

const ZERO: u64 = 0

§

const ONE: u64 = 1

§

fn from_usize(v: usize) -> u64

§

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

§

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

§

impl CacheKey for u128

§

const BITS_COUNT: u32 = 128

§

const ZERO: u128 = 0

§

const ONE: u128 = 1

§

fn from_usize(v: usize) -> u128

§

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

§

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

§

impl CacheKey for BUint<bnum::::types::U256::{constant#0}>

§

const BITS_COUNT: u32 = 256

§

const ZERO: BUint<bnum::::types::U256::{constant#0}> = U256::ZERO

§

const ONE: BUint<bnum::::types::U256::{constant#0}> = U256::ONE

§

fn from_usize(v: usize) -> BUint<bnum::::types::U256::{constant#0}>

§

fn checked_mul( self, rhs: BUint<bnum::::types::U256::{constant#0}>, ) -> Option<BUint<bnum::::types::U256::{constant#0}>>

§

fn wrapping_add( self, rhs: BUint<bnum::::types::U256::{constant#0}>, ) -> BUint<bnum::::types::U256::{constant#0}>

§

impl CacheKey for BUint<bnum::::types::U512::{constant#0}>

§

const BITS_COUNT: u32 = 512

§

const ZERO: BUint<bnum::::types::U512::{constant#0}> = U512::ZERO

§

const ONE: BUint<bnum::::types::U512::{constant#0}> = U512::ONE

§

fn from_usize(v: usize) -> BUint<bnum::::types::U512::{constant#0}>

§

fn checked_mul( self, rhs: BUint<bnum::::types::U512::{constant#0}>, ) -> Option<BUint<bnum::::types::U512::{constant#0}>>

§

fn wrapping_add( self, rhs: BUint<bnum::::types::U512::{constant#0}>, ) -> BUint<bnum::::types::U512::{constant#0}>

§

impl CacheKey for BUint<bnum::::types::U1024::{constant#0}>

§

const BITS_COUNT: u32 = 1024

§

const ZERO: BUint<bnum::::types::U1024::{constant#0}> = U1024::ZERO

§

const ONE: BUint<bnum::::types::U1024::{constant#0}> = U1024::ONE

§

fn from_usize(v: usize) -> BUint<bnum::::types::U1024::{constant#0}>

§

fn checked_mul( self, rhs: BUint<bnum::::types::U1024::{constant#0}>, ) -> Option<BUint<bnum::::types::U1024::{constant#0}>>

§

fn wrapping_add( self, rhs: BUint<bnum::::types::U1024::{constant#0}>, ) -> BUint<bnum::::types::U1024::{constant#0}>

Implementors§