Module storage

Module storage 

Source
Expand description

Global persistent storage. Nice for some global game configs available everywhere. Yes, singletons available right here, with a nice API and some safety. Global read-only storage

use macroquad::experimental::collections::storage;

struct WorldBoundaries(i32);

fn draw_player() {
  let boundaries: i32 = storage::get::<WorldBoundaries>().0;
  assert_eq!(boundaries, 23);
}

storage::store(WorldBoundaries(23));
draw_player();

Functionsยง

get
Get reference to data from global storage. Will panic if there is no data available with this type.
get_mut
Get mutable reference to data from global storage. Will panic if there is no data available with this type.
store
Store data in global storage. Will silently overwrite an old value if any.
try_get
Get reference to data from global storage. Will return None if there is no data available with this type.
try_get_mut
Get mutable reference to data from global storage. Will return None if there is no data available with this type.