[−][src]Struct stadium::Stadium
A chunk of allocated memory that stores a bunch of values of different types.
Example
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 Stadium
[src]
pub fn builder() -> Builder
[src]
Creates a new Builder
.
Example
use stadium::Stadium; let builder = Stadium::builder();
Builder
struct.Builder.html
pub fn is_associated_with<T>(&self, handle: Handle<T>) -> bool
[src]
Checks if the given Handle
can be safely used with this Stadium
.
Example
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>(&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.
Example
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>(&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.
Example
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>(&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.
Example
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>(&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.
Example
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>(&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.
Example
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>(&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.
Example
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 thisStadium
. - The returned pointer is used as if it was a
*const T
whereT
is the type of the originalHandle
(it wasHandle<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 thisStadium
. - The returned pointer is used as if it was a
*mut T
whereT
is the type of the originalHandle
(it wasHandle<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>(&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>(&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>(&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
andb
must both be associated with thisStadium
. a
must be different fromb
Example
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>(&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.
Example
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 From<Builder> for Stadium
[src]
impl<T> Index<Handle<T>> for Stadium
[src]
type Output = T
The returned type after indexing.
pub fn index(&self, handle: Handle<T>) -> &Self::Output
[src]
impl<T> IndexMut<Handle<T>> for Stadium
[src]
Auto Trait Implementations
impl RefUnwindSafe for Stadium
[src]
impl !Send for Stadium
[src]
impl !Sync for Stadium
[src]
impl Unpin for Stadium
[src]
impl UnwindSafe for Stadium
[src]
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,