Struct block_id::BlockId

source ·
pub struct BlockId<T: Copy + Hash + Eq> { /* private fields */ }
Expand description

Represents a specific, deterministic two-way mapping between u64 values and opaque IDs.

For BlockId<char>, additional functionality is provided for mapping between u64s and Strings.

Implementations§

source§

impl<T: Copy + Hash + Eq> BlockId<T>

source

pub fn new(alphabet: Alphabet<T>, seed: u128, min_length: u8) -> Self

Construct a block ID mapping. Mappings are deterministic based on the three parameters passed at construction: the alphabet, seed, and minimum length.

source

pub fn encode(&self, v: u64) -> Option<Vec<T>>

Encode a given u64 into an opaque Vec<T>.

source

pub fn decode(&self, v: Vec<T>) -> Option<u64>

Decode an opaque Vec<T> from a given u64.

source§

impl BlockId<char>

For the special case of BlockId<char>, helper encoders/decoders that use strings rather than vectors are provided.

source

pub fn encode_string(&self, v: u64) -> Option<String>

Encode a u64 into an opaque string.

source

pub fn decode_string(&self, v: &str) -> Option<u64>

Decode a u64 from an opaque string.

Trait Implementations§

source§

impl<T: Clone + Copy + Hash + Eq> Clone for BlockId<T>

source§

fn clone(&self) -> BlockId<T>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<T: Copy + Hash + Eq> Debug for BlockId<T>

source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<T> RefUnwindSafe for BlockId<T>where T: RefUnwindSafe,

§

impl<T> Send for BlockId<T>where T: Send,

§

impl<T> Sync for BlockId<T>where T: Sync,

§

impl<T> Unpin for BlockId<T>where T: Unpin,

§

impl<T> UnwindSafe for BlockId<T>where T: UnwindSafe,

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere 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 Twhere 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.
§

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

§

fn vzip(self) -> V