pub struct AllStoragesView<'a>(/* private fields */);
Expand description
Shared view over AllStorages
.
Methods from Deref<Target = AllStorages>§
Sourcepub fn add_unique<T: Send + Sync + Unique>(&self, component: T)
pub fn add_unique<T: Send + Sync + Unique>(&self, component: T)
Adds a new unique storage, unique storages store exactly one T
at any time.
To access a unique storage value, use UniqueView
or UniqueViewMut
.
§Example
use shipyard::{AllStoragesViewMut, Unique, World};
#[derive(Unique)]
struct USIZE(usize);
let world = World::new();
let mut all_storages = world.borrow::<AllStoragesViewMut>().unwrap();
all_storages.add_unique(USIZE(0));
Sourcepub fn add_unique_non_send<T: Sync + Unique>(&self, component: T)
pub fn add_unique_non_send<T: Sync + Unique>(&self, component: T)
Adds a new unique storage, unique storages store exactly one T
at any time.
To access a unique storage value, use NonSend and UniqueViewMut or UniqueViewMut.
Does nothing if the storage already exists.
Sourcepub fn add_unique_non_sync<T: Send + Unique>(&self, component: T)
pub fn add_unique_non_sync<T: Send + Unique>(&self, component: T)
Adds a new unique storage, unique storages store exactly one T
at any time.
To access a unique storage value, use NonSync and UniqueViewMut or UniqueViewMut.
Does nothing if the storage already exists.
Sourcepub fn add_unique_non_send_sync<T: Unique>(&self, component: T)
pub fn add_unique_non_send_sync<T: Unique>(&self, component: T)
Adds a new unique storage, unique storages store exactly one T
at any time.
To access a unique storage value, use NonSync and UniqueViewMut or UniqueViewMut.
Does nothing if the storage already exists.
Sourcepub fn remove_unique<T: Unique>(&self) -> Result<T, UniqueRemove>
pub fn remove_unique<T: Unique>(&self) -> Result<T, UniqueRemove>
Removes a unique storage.
§Borrows
T
storage (exclusive)
§Errors
T
storage borrow failed.T
storage did not exist.
§Example
use shipyard::{AllStoragesViewMut, Unique, World};
#[derive(Unique)]
struct USIZE(usize);
let world = World::new();
let mut all_storages = world.borrow::<AllStoragesViewMut>().unwrap();
all_storages.add_unique(USIZE(0));
let i = all_storages.remove_unique::<USIZE>().unwrap();
Sourcepub fn borrow<V: Borrow>(&self) -> Result<V::View<'_>, GetStorage>
pub fn borrow<V: Borrow>(&self) -> Result<V::View<'_>, GetStorage>
Borrows the requested storage(s), if it doesn’t exist it’ll get created.
You can use a tuple to get multiple storages at once.
You can use:
- View<T> for a shared access to
T
storage - ViewMut<T> for an exclusive access to
T
storage - EntitiesView for a shared access to the entity storage
- EntitiesViewMut for an exclusive reference to the entity storage
- UniqueView<T> for a shared access to a
T
unique storage - UniqueViewMut<T> for an exclusive access to a
T
unique storage Option<V>
with one or multiple views for fallible access to one or more storages- This is supported on
feature=“thread_local”
only:- NonSend<View<T>> for a shared access to a
T
storage whereT
isn’tSend
- NonSend<ViewMut<T>> for an exclusive access to a
T
storage whereT
isn’tSend
NonSend and UniqueView/UniqueViewMut can be used together to access a!Send
unique storage. - NonSync<View<T>> for a shared access to a
T
storage whereT
isn’tSync
- NonSync<ViewMut<T>> for an exclusive access to a
T
storage whereT
isn’tSync
NonSync and UniqueView/UniqueViewMut can be used together to access a!Sync
unique storage. - NonSendSync<View<T>> for a shared access to a
T
storage whereT
isn’tSend
norSync
- NonSendSync<ViewMut<T>> for an exclusive access to a
T
storage whereT
isn’tSend
norSync
NonSendSync and UniqueView/UniqueViewMut can be used together to access a!Send + !Sync
unique storage.
- NonSend<View<T>> for a shared access to a
§Borrows
- Storage (exclusive or shared)
§Errors
- Storage borrow failed.
- Unique storage did not exist.
§Example
use shipyard::{AllStoragesViewMut, Component, EntitiesView, View, ViewMut, World};
#[derive(Component)]
struct U32(u32);
#[derive(Component)]
struct USIZE(usize);
let world = World::new();
let all_storages = world.borrow::<AllStoragesViewMut>().unwrap();
let u32s = all_storages.borrow::<View<U32>>().unwrap();
let (entities, mut usizes) = all_storages
.borrow::<(EntitiesView, ViewMut<USIZE>)>()
.unwrap();
Sourcepub fn run_with_data<Data, B, S: AllSystem<(Data,), B>>(
&self,
system: S,
data: Data,
) -> S::Return
pub fn run_with_data<Data, B, S: AllSystem<(Data,), B>>( &self, system: S, data: Data, ) -> S::Return
Borrows the requested storages, runs the function and evaluates to the function’s return value.
Data can be passed to the function, this always has to be a single type but you can use a tuple if needed.
You can use:
- View<T> for a shared access to
T
storage - ViewMut<T> for an exclusive access to
T
storage - EntitiesView for a shared access to the entity storage
- EntitiesViewMut for an exclusive reference to the entity storage
- UniqueView<T> for a shared access to a
T
unique storage - UniqueViewMut<T> for an exclusive access to a
T
unique storage Option<V>
with one or multiple views for fallible access to one or more storages- This is supported on
feature=“thread_local”
only:- NonSend<View<T>> for a shared access to a
T
storage whereT
isn’tSend
- NonSend<ViewMut<T>> for an exclusive access to a
T
storage whereT
isn’tSend
NonSend and UniqueView/UniqueViewMut can be used together to access a!Send
unique storage. - NonSync<View<T>> for a shared access to a
T
storage whereT
isn’tSync
- NonSync<ViewMut<T>> for an exclusive access to a
T
storage whereT
isn’tSync
NonSync and UniqueView/UniqueViewMut can be used together to access a!Sync
unique storage. - NonSendSync<View<T>> for a shared access to a
T
storage whereT
isn’tSend
norSync
- NonSendSync<ViewMut<T>> for an exclusive access to a
T
storage whereT
isn’tSend
norSync
NonSendSync and UniqueView/UniqueViewMut can be used together to access a!Send + !Sync
unique storage.
- NonSend<View<T>> for a shared access to a
§Borrows
- Storage (exclusive or shared)
§Panics
- Storage borrow failed.
- Unique storage did not exist.
- Error returned by user.
Sourcepub fn run<B, S: AllSystem<(), B>>(&self, system: S) -> S::Return
pub fn run<B, S: AllSystem<(), B>>(&self, system: S) -> S::Return
Borrows the requested storages, runs the function and evaluates to the function’s return value.
You can use:
- View<T> for a shared access to
T
storage - ViewMut<T> for an exclusive access to
T
storage - EntitiesView for a shared access to the entity storage
- EntitiesViewMut for an exclusive reference to the entity storage
- UniqueView<T> for a shared access to a
T
unique storage - UniqueViewMut<T> for an exclusive access to a
T
unique storage Option<V>
with one or multiple views for fallible access to one or more storages- This is supported on
feature=“thread_local”
only:- NonSend<View<T>> for a shared access to a
T
storage whereT
isn’tSend
- NonSend<ViewMut<T>> for an exclusive access to a
T
storage whereT
isn’tSend
NonSend and UniqueView/UniqueViewMut can be used together to access a!Send
unique storage. - NonSync<View<T>> for a shared access to a
T
storage whereT
isn’tSync
- NonSync<ViewMut<T>> for an exclusive access to a
T
storage whereT
isn’tSync
NonSync and UniqueView/UniqueViewMut can be used together to access a!Sync
unique storage. - NonSendSync<View<T>> for a shared access to a
T
storage whereT
isn’tSend
norSync
- NonSendSync<ViewMut<T>> for an exclusive access to a
T
storage whereT
isn’tSend
norSync
NonSendSync and UniqueView/UniqueViewMut can be used together to access a!Send + !Sync
unique storage.
- NonSend<View<T>> for a shared access to a
§Borrows
- Storage (exclusive or shared)
§Panics
- Storage borrow failed.
- Unique storage did not exist.
- Error returned by user.
§Example
use shipyard::{AllStoragesViewMut, Component, View, ViewMut, World};
#[derive(Component)]
struct I32(i32);
#[derive(Component)]
struct U32(u32);
#[derive(Component)]
struct USIZE(usize);
fn sys1(i32s: View<I32>) -> i32 {
0
}
let world = World::new();
let all_storages = world.borrow::<AllStoragesViewMut>().unwrap();
all_storages
.run(|usizes: View<USIZE>, mut u32s: ViewMut<U32>| {
// -- snip --
});
let i = all_storages.run(sys1);
Sourcepub fn memory_usage(&self) -> AllStoragesMemoryUsage<'_>
pub fn memory_usage(&self) -> AllStoragesMemoryUsage<'_>
Displays storages memory information.
Sourcepub fn get_tracking_timestamp(&self) -> TrackingTimestamp
pub fn get_tracking_timestamp(&self) -> TrackingTimestamp
Returns a timestamp used to clear tracking information.
Sourcepub fn get<T: GetComponent>(
&self,
entity: EntityId,
) -> Result<T::Out<'_>, GetComponent>
pub fn get<T: GetComponent>( &self, entity: EntityId, ) -> Result<T::Out<'_>, GetComponent>
Retrieve components of entity
.
Multiple components can be queried at the same time using a tuple.
You can use:
&T
for a shared access toT
component&mut T
for an exclusive access toT
component- This is supported on
feature=“thread_local”
only: - NonSend<&T> for a shared access to a
T
component whereT
isn’tSend
- NonSend<&mut T> for an exclusive access to a
T
component whereT
isn’tSend
- NonSync<&T> for a shared access to a
T
component whereT
isn’tSync
- NonSync<&mut T> for an exclusive access to a
T
component whereT
isn’tSync
- NonSendSync<&T> for a shared access to a
T
component whereT
isn’tSend
norSync
- NonSendSync<&mut T> for an exclusive access to a
T
component whereT
isn’tSend
norSync
§Borrows
- AllStorages (shared) + storage (exclusive or shared)
§Errors
- AllStorages borrow failed.
- Storage borrow failed.
- Entity does not have the component.
§Example
use shipyard::{AllStoragesViewMut, Component, World};
#[derive(Component, Debug, PartialEq, Eq)]
struct U32(u32);
#[derive(Component, Debug, PartialEq, Eq)]
struct USIZE(usize);
let world = World::new();
let mut all_storages = world.borrow::<AllStoragesViewMut>().unwrap();
let entity = all_storages.add_entity((USIZE(0), U32(1)));
let (i, j) = all_storages.get::<(&USIZE, &mut U32)>(entity).unwrap();
assert!(*i == &USIZE(0));
assert!(*j == &U32(1));
Sourcepub fn get_unique<T: GetUnique>(&self) -> Result<T::Out<'_>, GetStorage>
pub fn get_unique<T: GetUnique>(&self) -> Result<T::Out<'_>, GetStorage>
Retrieve a unique component.
You can use:
&T
for a shared access toT
unique component&mut T
for an exclusive access toT
unique component- This is supported on
feature=“thread_local”
only: - NonSend<&T> for a shared access to a
T
unique component whereT
isn’tSend
- NonSend<&mut T> for an exclusive access to a
T
unique component whereT
isn’tSend
- NonSync<&T> for a shared access to a
T
unique component whereT
isn’tSync
- NonSync<&mut T> for an exclusive access to a
T
unique component whereT
isn’tSync
- NonSendSync<&T> for a shared access to a
T
unique component whereT
isn’tSend
norSync
- NonSendSync<&mut T> for an exclusive access to a
T
unique component whereT
isn’tSend
norSync
§Borrows
- AllStorages (shared) + storage (exclusive or shared)
§Errors
- AllStorages borrow failed.
- Storage borrow failed.
§Example
use shipyard::{AllStoragesViewMut, Unique, World};
#[derive(Unique, Debug, PartialEq, Eq)]
struct U32(u32);
let world = World::new();
let mut all_storages = world.borrow::<AllStoragesViewMut>().unwrap();
all_storages.add_unique(U32(0));
let i = all_storages.get_unique::<&U32>().unwrap();
assert!(*i == U32(0));
Sourcepub fn iter<'a, T: IterComponent>(&'a self) -> IntoIterRef<'a, T>
pub fn iter<'a, T: IterComponent>(&'a self) -> IntoIterRef<'a, T>
Iterate components.
Multiple components can be iterated at the same time using a tuple.
You can use:
&T
for a shared access toT
component&mut T
for an exclusive access toT
component- This is supported on
feature=“thread_local”
only: - NonSend<&T> for a shared access to a
T
component whereT
isn’tSend
- NonSend<&mut T> for an exclusive access to a
T
component whereT
isn’tSend
- NonSync<&T> for a shared access to a
T
component whereT
isn’tSync
- NonSync<&mut T> for an exclusive access to a
T
component whereT
isn’tSync
- NonSendSync<&T> for a shared access to a
T
component whereT
isn’tSend
norSync
- NonSendSync<&mut T> for an exclusive access to a
T
component whereT
isn’tSend
norSync
§Borrows
- AllStorages (shared)
§Panics
- AllStorages borrow failed.
§Example
use shipyard::{AllStoragesViewMut, Component, World};
#[derive(Component, Debug, PartialEq, Eq)]
struct U32(u32);
#[derive(Component, Debug, PartialEq, Eq)]
struct USIZE(usize);
let world = World::new();
let mut all_storages = world.borrow::<AllStoragesViewMut>().unwrap();
let entity = all_storages.add_entity((USIZE(0), U32(1)));
let mut iter = all_storages.iter::<(&USIZE, &mut U32)>();
for (i, j) in &mut iter {
// <-- SNIP -->
}
Trait Implementations§
Source§impl AsRef<AllStorages> for AllStoragesView<'_>
impl AsRef<AllStorages> for AllStoragesView<'_>
Source§fn as_ref(&self) -> &AllStorages
fn as_ref(&self) -> &AllStorages
Source§impl<'a> BorrowInfo for AllStoragesView<'a>
impl<'a> BorrowInfo for AllStoragesView<'a>
Source§fn borrow_info(info: &mut Vec<TypeInfo>)
fn borrow_info(info: &mut Vec<TypeInfo>)
Source§fn enable_tracking(_: &mut Vec<fn(&AllStorages) -> Result<(), GetStorage>>)
fn enable_tracking(_: &mut Vec<fn(&AllStorages) -> Result<(), GetStorage>>)
World
where this storage is borrowed.Source§impl Clone for AllStoragesView<'_>
impl Clone for AllStoragesView<'_>
Source§impl Deref for AllStoragesView<'_>
impl Deref for AllStoragesView<'_>
Source§impl WorldBorrow for AllStoragesView<'_>
impl WorldBorrow for AllStoragesView<'_>
type WorldView<'a> = AllStoragesView<'a>
Source§fn world_borrow(
world: &World,
_last_run: Option<TrackingTimestamp>,
_current: TrackingTimestamp,
) -> Result<Self::WorldView<'_>, GetStorage>
fn world_borrow( world: &World, _last_run: Option<TrackingTimestamp>, _current: TrackingTimestamp, ) -> Result<Self::WorldView<'_>, GetStorage>
Auto Trait Implementations§
impl<'a> Freeze for AllStoragesView<'a>
impl<'a> !RefUnwindSafe for AllStoragesView<'a>
impl<'a> Send for AllStoragesView<'a>
impl<'a> Sync for AllStoragesView<'a>
impl<'a> Unpin for AllStoragesView<'a>
impl<'a> !UnwindSafe for AllStoragesView<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more