pub struct DungeonCore<const SIZE: usize, const ALIGN: u8 = 3>where
    Alignment<ALIGN>: ValidAlignment,
{ /* private fields */ }
Expand description

Core of a dungeon primitive.

Any static type with size less than or equal to SIZE bytes and alignment requirements less than or equal to 2^ALIGN bytes can be stored in the core.

By default, this type uses a 8 byte alignment as that is the most common alignment for x64 machines.

Implementations§

Create a empty dungeon core.

Examples found in repository?
examples/core.rs (line 4)
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
fn main() {
    let mut x = DungeonCore::<24>::new();

    x.store(1234_i32);
    dbg!(x.take::<i32>());

    x.store(1.234_f32);
    dbg!(x.take::<f32>());

    x.store(1234_i32);
    dbg!(x.take::<f32>());

    x.store("hello");
    dbg!(x.take::<&'static str>());

    x.store("world".to_owned());
    dbg!(x.take::<String>());

    x.store("a".to_owned());
    x.store("b".to_owned());
    dbg!(x.take::<String>());
}

Store a value of type T.

If T can not be stored by this dungeon core do to size or alignment requirements a compiler error or runtime panic will be generated. This behavior is controlled by the assert_runtime feature.

If the dungeon core contains a value already it will be dropped.

Examples found in repository?
examples/core.rs (line 6)
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
fn main() {
    let mut x = DungeonCore::<24>::new();

    x.store(1234_i32);
    dbg!(x.take::<i32>());

    x.store(1.234_f32);
    dbg!(x.take::<f32>());

    x.store(1234_i32);
    dbg!(x.take::<f32>());

    x.store("hello");
    dbg!(x.take::<&'static str>());

    x.store("world".to_owned());
    dbg!(x.take::<String>());

    x.store("a".to_owned());
    x.store("b".to_owned());
    dbg!(x.take::<String>());
}

Gain ownership of the value inside the dungeon core.

This will leave the dungeon core empty if the value is of type T. If the dungeon core is empty or has another type’s value stored in it then a None will be returned.

Examples found in repository?
examples/core.rs (line 7)
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
fn main() {
    let mut x = DungeonCore::<24>::new();

    x.store(1234_i32);
    dbg!(x.take::<i32>());

    x.store(1.234_f32);
    dbg!(x.take::<f32>());

    x.store(1234_i32);
    dbg!(x.take::<f32>());

    x.store("hello");
    dbg!(x.take::<&'static str>());

    x.store("world".to_owned());
    dbg!(x.take::<String>());

    x.store("a".to_owned());
    x.store("b".to_owned());
    dbg!(x.take::<String>());
}

Replace the current value with a T.

The current value is returned if the dungeon core is not empty, and the current stored value is of type U.

If T can not be stored by this dungeon core do to size or alignment requirements a compiler error or runtime panic will be generated. This behavior is controlled by the assert_runtime feature.

This is slightly more efficient than a take() followed be a `store()

Try to borrow the stored value.

If the dungeon core is empty or the stored value is not of type T then None will be returned.

Try to mutably borrow the stored value.

If the dungeon core is empty or the stored value is not of type T then None will be returned.

Check if a value is being stored.

Check if a value being stored is of type T.

Will always return false if empty.

Unsafe methods.

Unchecked form of store.

If the dungeon core is not empty, then the stored value will be forgotten.

Safety

T must be storable in SIZE bytes with alignment of 2^ALIGN bytes.

Unchecked form of [take].

Safety

The dungeon core must be storing a valid value of type T.

Unchecked form of try_borrow.

Safety

The dungeon core must be storing a valid value of type T.

Unchecked form of try_borrow_mut.

Safety

The dungeon core must be storing a valid value of type T.

Trait Implementations§

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.