[][src]Struct idcontain::Id

pub struct Id<T> { /* fields omitted */ }

The Id of an element of type T as returned by IdSlab insertions.

Id-s are opaque, but Copy, comparable and hashable. Think of an Id as a safe *const T which you can dereference if you have a reference to the originating IdSlab.

Implementation

Internally an Id is implemented as an (index, tag) pair. The index points to a slot in the IdSlab, while the tag allows disambiguating between values when a slot gets reused (a matching tag is stored in the slot and is incremented every time a value is removed from that slot).

Methods

impl<T> Id<T>[src]

pub fn invalid() -> Self[src]

Returns an invalid Id (which will never be returned by a container).

Panics

None.

Example

let id_slab: IdSlab<&'static str> = IdSlab::new();
assert!(!id_slab.contains(Id::invalid()));

pub fn cast<U>(self) -> Id<U>[src]

Casts the Id to an Id of a different type.

This is handy when using IdSlab to generate proxy Id-s for an IdMap.

Panics

None.

Example

let mut id_slab: IdSlab<()> = IdSlab::new();
let id: Id<u32> = id_slab.insert(()).cast();

Trait Implementations

impl<T> Clone for Id<T>[src]

impl<T> Copy for Id<T>[src]

impl<T> Default for Id<T>[src]

impl<T> Eq for Id<T>[src]

impl<T> Ord for Id<T>[src]

impl<T> PartialEq<Id<T>> for Id<T>[src]

impl<T> PartialOrd<Id<T>> for Id<T>[src]

impl<T> Debug for Id<T>[src]

impl<T> Index<Id<T>> for IdSlab<T>[src]

type Output = T

The returned type after indexing.

impl<T> IndexMut<Id<T>> for IdSlab<T>[src]

impl<T> Hash for Id<T>[src]

Auto Trait Implementations

impl<T> Send for Id<T> where
    T: Send

impl<T> Sync for Id<T> where
    T: Sync

impl<T> Unpin for Id<T> where
    T: Unpin

impl<T> UnwindSafe for Id<T> where
    T: UnwindSafe

impl<T> RefUnwindSafe for Id<T> where
    T: RefUnwindSafe

Blanket Implementations

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> From<T> for T[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]