Trait IntKey

Source
pub trait IntKey: Copy {
    type Int: Int;

    const PRIME: Self::Int;

    // Required method
    fn into_int(self) -> Self::Int;
}
Expand description

A type that can be used as key for IntMap.

The type needs to be integer based, i.e. it can be represented by a unique integer. This can be useful for types that wraps integers for type safety (e.g. Ipv4Addr) or for enforcing invariants (e.g. NonZeroU64).

§Example

use intmap::{IntKey, IntMap};

#[derive(Clone, Copy)]
struct MyKey(u64);

impl IntKey for MyKey {
    type Int = u64;

    // You could also choose another prime number
    const PRIME: Self::Int = u64::PRIME;

    fn into_int(self) -> Self::Int {
        self.0
    }
}

let map: IntMap<MyKey, f32> = IntMap::new();

Required Associated Constants§

Source

const PRIME: Self::Int

The prime number used for hashing.

The choice might influence the number of key collisions which affects the performance.

Required Associated Types§

Source

type Int: Int

The underlying integer that will be used as actual key.

Required Methods§

Source

fn into_int(self) -> Self::Int

Converts the key into the underlying integer.

IntMap assumes that this is a cheap operation and that two different values don’t return the same integer.

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 IntKey for i8

Source§

const PRIME: Self::Int = {transmute(0xfb): <i8 as int_key::IntKey>::Int}

Source§

type Int = u8

Source§

fn into_int(self) -> Self::Int

Source§

impl IntKey for i16

Source§

const PRIME: Self::Int = {transmute(0xfff1): <i16 as int_key::IntKey>::Int}

Source§

type Int = u16

Source§

fn into_int(self) -> Self::Int

Source§

impl IntKey for i32

Source§

const PRIME: Self::Int = {transmute(0xfffffffb): <i32 as int_key::IntKey>::Int}

Source§

type Int = u32

Source§

fn into_int(self) -> Self::Int

Source§

impl IntKey for i64

Source§

const PRIME: Self::Int = {transmute(0xffffffffffffffc5): <i64 as int_key::IntKey>::Int}

Source§

type Int = u64

Source§

fn into_int(self) -> Self::Int

Source§

impl IntKey for i128

Source§

const PRIME: Self::Int = {transmute(0xffffffffffffffffffffffffffffff61): <i128 as int_key::IntKey>::Int}

Source§

type Int = u128

Source§

fn into_int(self) -> Self::Int

Source§

impl IntKey for isize

Source§

const PRIME: Self::Int = {transmute(0xfffffffb): <isize as int_key::IntKey>::Int}

Source§

type Int = usize

Source§

fn into_int(self) -> Self::Int

Source§

impl IntKey for u8

Source§

const PRIME: Self::Int = {transmute(0xfb): <u8 as int_key::IntKey>::Int}

Source§

type Int = u8

Source§

fn into_int(self) -> Self::Int

Source§

impl IntKey for u16

Source§

const PRIME: Self::Int = {transmute(0xfff1): <u16 as int_key::IntKey>::Int}

Source§

type Int = u16

Source§

fn into_int(self) -> Self::Int

Source§

impl IntKey for u32

Source§

const PRIME: Self::Int = {transmute(0xfffffffb): <u32 as int_key::IntKey>::Int}

Source§

type Int = u32

Source§

fn into_int(self) -> Self::Int

Source§

impl IntKey for u64

Source§

const PRIME: Self::Int = {transmute(0xffffffffffffffc5): <u64 as int_key::IntKey>::Int}

Source§

type Int = u64

Source§

fn into_int(self) -> Self::Int

Source§

impl IntKey for u128

Source§

const PRIME: Self::Int = {transmute(0xffffffffffffffffffffffffffffff61): <u128 as int_key::IntKey>::Int}

Source§

type Int = u128

Source§

fn into_int(self) -> Self::Int

Source§

impl IntKey for usize

Source§

const PRIME: Self::Int = {transmute(0xfffffffb): <usize as int_key::IntKey>::Int}

Source§

type Int = usize

Source§

fn into_int(self) -> Self::Int

Source§

impl IntKey for Ipv4Addr

Source§

const PRIME: Self::Int = {transmute(0xfffffffb): <std::net::Ipv4Addr as int_key::IntKey>::Int}

Source§

type Int = u32

Source§

fn into_int(self) -> Self::Int

Source§

impl IntKey for Ipv6Addr

Source§

const PRIME: Self::Int = {transmute(0xffffffffffffffffffffffffffffff61): <std::net::Ipv6Addr as int_key::IntKey>::Int}

Source§

type Int = u128

Source§

fn into_int(self) -> Self::Int

Source§

impl IntKey for NonZeroI8

Source§

const PRIME: Self::Int = {transmute(0xfb): <std::num::NonZero<i8> as int_key::IntKey>::Int}

Source§

type Int = <i8 as IntKey>::Int

Source§

fn into_int(self) -> Self::Int

Source§

impl IntKey for NonZeroI16

Source§

const PRIME: Self::Int = {transmute(0xfff1): <std::num::NonZero<i16> as int_key::IntKey>::Int}

Source§

type Int = <i16 as IntKey>::Int

Source§

fn into_int(self) -> Self::Int

Source§

impl IntKey for NonZeroI32

Source§

const PRIME: Self::Int = {transmute(0xfffffffb): <std::num::NonZero<i32> as int_key::IntKey>::Int}

Source§

type Int = <i32 as IntKey>::Int

Source§

fn into_int(self) -> Self::Int

Source§

impl IntKey for NonZeroI64

Source§

const PRIME: Self::Int = {transmute(0xffffffffffffffc5): <std::num::NonZero<i64> as int_key::IntKey>::Int}

Source§

type Int = <i64 as IntKey>::Int

Source§

fn into_int(self) -> Self::Int

Source§

impl IntKey for NonZeroIsize

Source§

const PRIME: Self::Int = {transmute(0xfffffffb): <std::num::NonZero<isize> as int_key::IntKey>::Int}

Source§

type Int = <isize as IntKey>::Int

Source§

fn into_int(self) -> Self::Int

Source§

impl IntKey for NonZeroU8

Source§

const PRIME: Self::Int = {transmute(0xfb): <std::num::NonZero<u8> as int_key::IntKey>::Int}

Source§

type Int = <u8 as IntKey>::Int

Source§

fn into_int(self) -> Self::Int

Source§

impl IntKey for NonZeroU16

Source§

const PRIME: Self::Int = {transmute(0xfff1): <std::num::NonZero<u16> as int_key::IntKey>::Int}

Source§

type Int = <u16 as IntKey>::Int

Source§

fn into_int(self) -> Self::Int

Source§

impl IntKey for NonZeroU32

Source§

const PRIME: Self::Int = {transmute(0xfffffffb): <std::num::NonZero<u32> as int_key::IntKey>::Int}

Source§

type Int = <u32 as IntKey>::Int

Source§

fn into_int(self) -> Self::Int

Source§

impl IntKey for NonZeroU64

Source§

const PRIME: Self::Int = {transmute(0xffffffffffffffc5): <std::num::NonZero<u64> as int_key::IntKey>::Int}

Source§

type Int = <u64 as IntKey>::Int

Source§

fn into_int(self) -> Self::Int

Source§

impl IntKey for NonZeroUsize

Source§

const PRIME: Self::Int = {transmute(0xfffffffb): <std::num::NonZero<usize> as int_key::IntKey>::Int}

Source§

type Int = <usize as IntKey>::Int

Source§

fn into_int(self) -> Self::Int

Source§

impl<K: IntKey> IntKey for Wrapping<K>

Source§

const PRIME: Self::Int = K::PRIME

Source§

type Int = <K as IntKey>::Int

Source§

fn into_int(self) -> Self::Int

Implementors§