Mapping

Struct Mapping 

Source
pub struct Mapping<T>(/* private fields */);
Expand description

A mapping between values and IDs.

This structure allows for bidirectional lookup between values and their assigned numeric IDs, with interior mutability for shared access.

Implementations§

Source§

impl<T: Ord + Clone> Mapping<T>

Source

pub fn new() -> Self

Creates a new empty mapping.

Source

pub fn register(&self, value: T) -> Id

Registers a new value in the mapping and returns its assigned ID.

Source

pub fn try_to_id(&self, value: &T) -> Option<Id>

Attempts to find the ID for a given value.

Source

pub fn to_id(&self, value: T) -> Id

Gets the ID for a value, registering it if not already present.

Source

pub fn to_data(&self, id: Id) -> Option<T>

Retrieves the data associated with an ID.

Source

pub fn binding(&self, source: &Binding<T>) -> Binding<Id>
where T: 'static,

Creates a binding that maps between a value binding and an ID binding.

This is useful for reactive UI systems where you need to work with IDs rather than the actual values but still maintain synchronization.

§Panics

Panics if the provided Id does not correspond to any value in the mapping.

Trait Implementations§

Source§

impl<T> Clone for Mapping<T>

Source§

fn clone(&self) -> Self

Creates a new reference to the same underlying mapping.

1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<T: Debug> Debug for Mapping<T>

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<T: Ord + Clone> Default for Mapping<T>

Source§

fn default() -> Self

Creates a new empty mapping.

Auto Trait Implementations§

§

impl<T> Freeze for Mapping<T>

§

impl<T> !RefUnwindSafe for Mapping<T>

§

impl<T> !Send for Mapping<T>

§

impl<T> !Sync for Mapping<T>

§

impl<T> Unpin for Mapping<T>

§

impl<T> !UnwindSafe for Mapping<T>

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> IdentifiableExt for T

Source§

fn use_id<F, Id>(self, f: F) -> UseId<Self, F>
where F: Fn(&Self) -> Id, Id: Ord + Hash,

Wraps the value in a UseId with the provided identification function.
Source§

fn self_id(self) -> SelfId<Self>

Wraps the value in a SelfId, making the value serve as its own identifier.
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> ToOwned for T
where T: Clone,

Source§

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