Struct rs_ecs::Resources[][src]

pub struct Resources(_);
Expand description

A type map for holding resources.

Resources replace global variables and my be accessed by systems that know their type.

Examples

struct MyResource(u32);

let mut resources = Resources::new();

// Insert multiple resources
resources.insert(42_u32);
resources.insert(MyResource(0));

// Borrow a resource immutably
let my_res = resources.get::<MyResource>();

// Borrow a resource mutably
let mut u32_res = resources.get_mut::<u32>();
*u32_res += 1;

Implementations

impl Resources[src]

pub fn new() -> Self[src]

Create an empty resources map. Synonym for Self::default().

impl Resources[src]

pub fn insert<R>(&mut self, res: R) where
    R: 'static, 
[src]

Insert a resource.

Panics

Panics if a resource of the same type is already present.

impl Resources[src]

pub fn get<R>(&self) -> Res<'_, R> where
    R: 'static, 
[src]

Borrow a resource immutably

Panics

Panics if the resource is not present.

pub fn get_mut<R>(&self) -> ResMut<'_, R> where
    R: 'static, 
[src]

Borrow a resource mutably

Panics

Panics if the resource is not present.

Trait Implementations

impl Default for Resources[src]

fn default() -> Self[src]

Create an empty resources map. Synonym for Self::new().

Auto Trait Implementations

impl !RefUnwindSafe for Resources

impl !Send for Resources

impl !Sync for Resources

impl Unpin for Resources

impl !UnwindSafe for Resources

Blanket Implementations

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

pub fn type_id(&self) -> TypeId[src]

Gets the TypeId of self. Read more

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

pub fn borrow(&self) -> &T[src]

Immutably borrows from an owned value. Read more

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

pub fn borrow_mut(&mut self) -> &mut T[src]

Mutably borrows from an owned value. Read more

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

pub fn from(t: T) -> T[src]

Performs the conversion.

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

pub fn into(self) -> U[src]

Performs the conversion.

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.

pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]

Performs the conversion.

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.

pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>[src]

Performs the conversion.