[][src]Struct oxygengine_core::ecs::shred::Resources

pub struct Resources { /* fields omitted */ }

A resource container, which provides methods to access to the contained resources.

Resource Ids

Resources are identified by ResourceIds, which consist of a TypeId.

Methods

impl Resources[src]

pub fn new() -> Resources[src]

Creates a new, empty resource container.

pub fn insert<R>(&mut self, r: R) where
    R: Resource
[src]

Inserts a resource into this container. If the resource existed before, it will be overwritten.

Examples

Every type satisfying Any + Debug + Send + Sync automatically implements Resource, thus can be added:

#[derive(Debug)]
struct MyRes(i32);

When you have a resource, simply insert it like this:

use shred::Resources;

let mut res = Resources::new();
res.insert(MyRes(5));

pub fn has_value<R>(&self) -> bool where
    R: Resource
[src]

Returns true if the specified resource type R exists in self.

pub fn has_value_raw(&self, id: ResourceId) -> bool[src]

Returns true if the specified resource type exists in self.

pub fn entry<R>(&mut self) -> Entry<R> where
    R: Resource
[src]

Returns an entry for the resource with type R.

pub fn fetch<T>(&self) -> Fetch<T> where
    T: Resource
[src]

Fetches the resource with the specified type T or panics if it doesn't exist.

Panics

Panics if the resource doesn't exist. Panics if the resource is being accessed mutably.

pub fn try_fetch<T>(&self) -> Option<Fetch<T>> where
    T: Resource
[src]

Like fetch, but returns an Option instead of inserting a default value in case the resource does not exist.

pub fn fetch_mut<T>(&self) -> FetchMut<T> where
    T: Resource
[src]

Fetches the resource with the specified type T mutably.

Please see fetch for details.

Panics

Panics if the resource doesn't exist. Panics if the resource is already being accessed.

pub fn try_fetch_mut<T>(&self) -> Option<FetchMut<T>> where
    T: Resource
[src]

Like fetch_mut, but returns an Option instead of inserting a default value in case the resource does not exist.

pub fn try_fetch_internal(
    &self,
    id: TypeId
) -> Option<&TrustCell<Box<dyn Resource + 'static>>>
[src]

Internal function for fetching resources, should only be used if you know what you're doing.

pub fn get_mut<T>(&mut self) -> Option<&mut T> where
    T: Resource
[src]

Retrieves a resource without fetching, which is cheaper, but only available with &mut self.

pub fn get_mut_raw(
    &mut self,
    id: TypeId
) -> Option<&mut (dyn Resource + 'static)>
[src]

Retrieves a resource without fetching, which is cheaper, but only available with &mut self.

Trait Implementations

impl Borrow<Resources> for World[src]

impl Default for Resources[src]

Auto Trait Implementations

Blanket Implementations

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

impl<T> Any for T where
    T: Any

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

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

impl<T> Erased for T

impl<T> Event for T where
    T: Send + Sync + 'static, 
[src]

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

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

impl<T> Resource for T where
    T: Any + Send + Sync
[src]

impl<T> TryDefault for T where
    T: Default
[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.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,