Struct stadium::Stadium[][src]

pub struct Stadium<'a> { /* fields omitted */ }

A chunk of allocated memory that stores a bunch of values of different types.

Examples

let mut builder = stadium::builder();

let h_vec = builder.insert(vec![1, 2, 3, 4]);
let h_string = builder.insert(String::from("Hello"));
let h_str = builder.insert("World");

let mut stadium = builder.build();

stadium[h_vec][0] = 2;
assert_eq!(&stadium[h_vec][..], &[2, 2, 3, 4]);

assert_eq!(stadium[h_str], "World");

Note that using a String or a Vec inside of a Stadium defies a bit of its original purpose (which is storing those different types localy in memory).

Implementations

impl<'a> Stadium<'a>[src]

pub fn builder() -> Builder<'a>[src]

Creates a new Builder.

Examples

use stadium::Stadium;

let builder = Stadium::builder();

Builder struct.Builder.html

pub fn is_associated_with<T: 'a>(&self, handle: Handle<T>) -> bool[src]

Checks if the given Handle can be safely used with this Stadium.

Examples

let mut builder_1 = stadium::builder();
let handle_1 = builder_1.insert("I'm a string inserted in the first stadium");
let stadium_1 = builder_1.build();

let mut builder_2 = stadium::builder();
let handle_2 = builder_2.insert("I'm a string inserted in the second stadium");
let stadium_2 = builder_2.build();

assert_eq!(stadium_1.is_associated_with(handle_2), false);
assert_eq!(stadium_1.is_associated_with(handle_1), true);
assert_eq!(stadium_2.is_associated_with(handle_2), true);
assert_eq!(stadium_2.is_associated_with(handle_1), false);

pub unsafe fn replace_unchecked<T: 'a>(
    &mut self,
    handle: Handle<T>,
    val: T
) -> T
[src]

Replaces the object referenced by the given Handle.

Safety

The provided Handle must be associated with this Stadium.

To check if a Handle can be safely used with a given Stadium, use the Stadium::is_associated_with function.

Examples

let mut builder = stadium::builder();
let handle = builder.insert(4);
let mut stadium = builder.build();

// SAFETY: The handle was created for this stadium.
unsafe {
    assert_eq!(stadium.replace_unchecked(handle, 5), 4);
    assert_eq!(stadium.get_unchecked(handle), &5);
}

pub fn replace<T: 'a>(&mut self, handle: Handle<T>, val: T) -> T[src]

Replaces the object referenced by the given Handle with the given value.

Panics

This function panics if handle is not associated with this Stadium.

To check if a Handle can be safely used with a given Stadium, use the Stadium::is_associated_with function.

Examples

let mut builder = stadium::builder();
let handle = builder.insert(5);
let mut stadium = builder.build();

assert_eq!(stadium.replace(handle, 6), 5);
assert_eq!(stadium.get(handle), &6);

pub fn get<T: 'a>(&self, handle: Handle<T>) -> &T[src]

Gets a reference to a value that is part of the Stadium.

Panics

This function panics if handle is not associated with this Stadium.

To check if a Handle can be safely used with a given Stadium, use the Stadium::is_associated_with function.

Examples

let mut builder = stadium::builder();

let h_num = builder.insert(2023);
let h_str = builder.insert("Hello, world");

let stadium = builder.build();

assert_eq!(stadium.get(h_str), &"Hello, world");
assert_eq!(stadium.get(h_num), &2023);

pub fn get_mut<T: 'a>(&mut self, handle: Handle<T>) -> &mut T[src]

Gets a reference to a value that is part of the Stadium.

Panics

This function panics if handle is not associated with this Stadium.

To check if a Handle can be safely used with a given Stadium, use the Stadium::is_associated_with function.

Examples

let mut builder = stadium::builder();

let h_num = builder.insert(250);
let h_vec = builder.insert(vec![1, 2, 3]);

let mut stadium = builder.build();

*stadium.get_mut(h_num) = 5;
stadium.get_mut(h_vec).push(4);

assert_eq!(stadium.get(h_num), &5);
assert_eq!(&stadium.get(h_vec)[..], &[1, 2, 3, 4])

pub unsafe fn get_unchecked<T: 'a>(&self, handle: Handle<T>) -> &T[src]

Gets a reference to a value that is part of the Stadium.

Safety

The provided Handle must be associated with this Stadium.

To check if a Handle can be safely used with a given Stadium, use the Stadium::is_associated_with function.

Examples

let mut builder = stadium::builder();
let handle = builder.insert(5);
let mut stadium = builder.build();

// SAFETY: The handle was provided by the builder of this stadium.
unsafe { assert_eq!(stadium.get_unchecked(handle), &5) };

pub unsafe fn get_unchecked_mut<T: 'a>(&mut self, handle: Handle<T>) -> &mut T[src]

Gets a reference to a value that is part of the Stadium.

Safety

The provided Handle must be associated with this Stadium.

To check if a Handle can be safely used with a given Stadium, use the Stadium::is_associated_with function.

Examples

let mut builder = stadium::builder();
let handle = builder.insert(5);
let mut stadium = builder.build();

// SAFETY: The handle was provided by the builder of this stadium.
unsafe {
    *stadium.get_unchecked_mut(handle) = 4;
    assert_eq!(stadium.get_unchecked(handle), &4);
}

pub unsafe fn get_ptr_raw(&self, handle: RawHandle) -> *const u8[src]

Gets a pointer to the element referenced by the given RawHandle.

Safety

This function is unsafe unless:

  • The given Handle is associated with this Stadium.
  • The returned pointer is used as if it was a *const T where T is the type of the original Handle (it was Handle<T>).

To check if a Handle can be safely used with a given Stadium, use the Stadium::is_associated_with function.

pub unsafe fn get_ptr_mut_raw(&mut self, handle: RawHandle) -> *mut u8[src]

Gets a pointer to the element referenced by the given RawHandle.

Safety

This function is unsafe unless:

  • The given Handle is associated with this Stadium.
  • The returned pointer is used as if it was a *mut T where T is the type of the original Handle (it was Handle<T>).

To check if a Handle can be safely used with a given Stadium, use the Stadium::is_associated_with function.

pub unsafe fn get_ptr<T: 'a>(&self, handle: Handle<T>) -> *const T[src]

Gets a pointer to the element referenced by the given Handle.

Safety

The given Handle must be associated with this Stadium.

To check if a Handle can be safely used with a given Stadium, use the Stadium::is_associated_with function.

pub unsafe fn get_ptr_mut<T: 'a>(&mut self, handle: Handle<T>) -> *mut T[src]

Gets a pointer to the element referenced by the given Handle.

Safety

The given Handle must be associated with this Stadium.

To check if a Handle can be safely used with a given Stadium, use the Stadium::is_associated_with function.

pub unsafe fn swap_unchecked<T: 'a>(&mut self, a: Handle<T>, b: Handle<T>)[src]

Swaps the values referenced by a and b within this Stadium.

Safety

  • This given handles a and b must both be associated with this Stadium.
  • a must be different from b

Examples

let mut builder = stadium::builder();
let a = builder.insert("Foo");
let b = builder.insert("Bar");
let mut s = builder.build();

assert_eq!(s[a], "Foo");
assert_eq!(s[b], "Bar");

// SAFETY: Those two handles are associated with `s`.
unsafe { s.swap_unchecked(a, b); }

assert_eq!(s[a], "Bar");
assert_eq!(s[b], "Foo");

pub fn swap<T: 'a>(&mut self, a: Handle<T>, b: Handle<T>)[src]

Swaps the values referenced by a and b within this Stadium.

Panics

This function panics if one of a or b is not associated with tihs Stadium.

To check if a Handle can be safely used with a given Stadium, use the Stadium::is_associated_with function.

Examples

let mut builder = stadium::builder();
let a = builder.insert("Foo");
let b = builder.insert("Bar");
let mut s = builder.build();

assert_eq!(s[a], "Foo");
assert_eq!(s[b], "Bar");

s.swap(a, b);

assert_eq!(s[a], "Bar");
assert_eq!(s[b], "Foo");

Trait Implementations

impl Drop for Stadium<'_>[src]

impl<'a> From<Builder<'a>> for Stadium<'a>[src]

impl<'a, T: 'a> Index<Handle<T>> for Stadium<'a>[src]

type Output = T

The returned type after indexing.

impl<'a, T: 'a> IndexMut<Handle<T>> for Stadium<'a>[src]

Auto Trait Implementations

impl<'a> RefUnwindSafe for Stadium<'a>

impl<'a> !Send for Stadium<'a>

impl<'a> !Sync for Stadium<'a>

impl<'a> Unpin for Stadium<'a>

impl<'a> UnwindSafe for Stadium<'a>

Blanket Implementations

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

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

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

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

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

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.