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)
Available on crate feature thread_local only.
pub fn add_unique_non_send<T: Sync + Unique>(&self, component: T)
thread_local only.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)
Available on crate feature thread_local only.
pub fn add_unique_non_sync<T: Send + Unique>(&self, component: T)
thread_local only.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)
Available on crate feature thread_local only.
pub fn add_unique_non_send_sync<T: Unique>(&self, component: T)
thread_local only.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
Tstorage (exclusive)
§Errors
Tstorage borrow failed.Tstorage 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
Tstorage - ViewMut<T> for an exclusive access to
Tstorage - 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
Tunique storage - UniqueViewMut<T> for an exclusive access to a
Tunique 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
Tstorage whereTisn’tSend - NonSend<ViewMut<T>> for an exclusive access to a
Tstorage whereTisn’tSend
NonSend and UniqueView/UniqueViewMut can be used together to access a!Sendunique storage. - NonSync<View<T>> for a shared access to a
Tstorage whereTisn’tSync - NonSync<ViewMut<T>> for an exclusive access to a
Tstorage whereTisn’tSync
NonSync and UniqueView/UniqueViewMut can be used together to access a!Syncunique storage. - NonSendSync<View<T>> for a shared access to a
Tstorage whereTisn’tSendnorSync - NonSendSync<ViewMut<T>> for an exclusive access to a
Tstorage whereTisn’tSendnorSync
NonSendSync and UniqueView/UniqueViewMut can be used together to access a!Send + !Syncunique 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
Tstorage - ViewMut<T> for an exclusive access to
Tstorage - 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
Tunique storage - UniqueViewMut<T> for an exclusive access to a
Tunique 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
Tstorage whereTisn’tSend - NonSend<ViewMut<T>> for an exclusive access to a
Tstorage whereTisn’tSend
NonSend and UniqueView/UniqueViewMut can be used together to access a!Sendunique storage. - NonSync<View<T>> for a shared access to a
Tstorage whereTisn’tSync - NonSync<ViewMut<T>> for an exclusive access to a
Tstorage whereTisn’tSync
NonSync and UniqueView/UniqueViewMut can be used together to access a!Syncunique storage. - NonSendSync<View<T>> for a shared access to a
Tstorage whereTisn’tSendnorSync - NonSendSync<ViewMut<T>> for an exclusive access to a
Tstorage whereTisn’tSendnorSync
NonSendSync and UniqueView/UniqueViewMut can be used together to access a!Send + !Syncunique 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
Tstorage - ViewMut<T> for an exclusive access to
Tstorage - 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
Tunique storage - UniqueViewMut<T> for an exclusive access to a
Tunique 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
Tstorage whereTisn’tSend - NonSend<ViewMut<T>> for an exclusive access to a
Tstorage whereTisn’tSend
NonSend and UniqueView/UniqueViewMut can be used together to access a!Sendunique storage. - NonSync<View<T>> for a shared access to a
Tstorage whereTisn’tSync - NonSync<ViewMut<T>> for an exclusive access to a
Tstorage whereTisn’tSync
NonSync and UniqueView/UniqueViewMut can be used together to access a!Syncunique storage. - NonSendSync<View<T>> for a shared access to a
Tstorage whereTisn’tSendnorSync - NonSendSync<ViewMut<T>> for an exclusive access to a
Tstorage whereTisn’tSendnorSync
NonSendSync and UniqueView/UniqueViewMut can be used together to access a!Send + !Syncunique 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:
&Tfor a shared access toTcomponent&mut Tfor an exclusive access toTcomponent- This is supported on
feature=“thread_local”only: - NonSend<&T> for a shared access to a
Tcomponent whereTisn’tSend - NonSend<&mut T> for an exclusive access to a
Tcomponent whereTisn’tSend - NonSync<&T> for a shared access to a
Tcomponent whereTisn’tSync - NonSync<&mut T> for an exclusive access to a
Tcomponent whereTisn’tSync - NonSendSync<&T> for a shared access to a
Tcomponent whereTisn’tSendnorSync - NonSendSync<&mut T> for an exclusive access to a
Tcomponent whereTisn’tSendnorSync
§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:
&Tfor a shared access toTunique component&mut Tfor an exclusive access toTunique component- This is supported on
feature=“thread_local”only: - NonSend<&T> for a shared access to a
Tunique component whereTisn’tSend - NonSend<&mut T> for an exclusive access to a
Tunique component whereTisn’tSend - NonSync<&T> for a shared access to a
Tunique component whereTisn’tSync - NonSync<&mut T> for an exclusive access to a
Tunique component whereTisn’tSync - NonSendSync<&T> for a shared access to a
Tunique component whereTisn’tSendnorSync - NonSendSync<&mut T> for an exclusive access to a
Tunique component whereTisn’tSendnorSync
§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:
&Tfor a shared access toTcomponent&mut Tfor an exclusive access toTcomponent- This is supported on
feature=“thread_local”only: - NonSend<&T> for a shared access to a
Tcomponent whereTisn’tSend - NonSend<&mut T> for an exclusive access to a
Tcomponent whereTisn’tSend - NonSync<&T> for a shared access to a
Tcomponent whereTisn’tSync - NonSync<&mut T> for an exclusive access to a
Tcomponent whereTisn’tSync - NonSendSync<&T> for a shared access to a
Tcomponent whereTisn’tSendnorSync - NonSendSync<&mut T> for an exclusive access to a
Tcomponent whereTisn’tSendnorSync
§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 -->
}Sourcepub fn clone_storages_to(&self, other: &mut AllStorages)
pub fn clone_storages_to(&self, other: &mut AllStorages)
Clones all storages with a registered clone function from this AllStorages to other.
Tracking is not cloned. Components will count as inserted in other.
Sourcepub fn clone_entity_to(
&self,
other_all_storages: &mut AllStorages,
entity: EntityId,
)
pub fn clone_entity_to( &self, other_all_storages: &mut AllStorages, entity: EntityId, )
Clones entity from this AllStorages to other_all_storages alongside all its with a registered clone function.
Sourcepub fn clone_components_to(
&self,
other_all_storages: &mut AllStorages,
from: EntityId,
to: EntityId,
)
pub fn clone_components_to( &self, other_all_storages: &mut AllStorages, from: EntityId, to: EntityId, )
Clones all components of from entity with a registered clone function from
this AllStorages to other_all_storages’s to entity.
Sourcepub fn serialize<'a, S: Serializer, V: Borrow>(
&'a self,
serializer: S,
) -> Result<S::Ok, Serialize<S>>
Available on crate feature serde1 only.
pub fn serialize<'a, S: Serializer, V: Borrow>( &'a self, serializer: S, ) -> Result<S::Ok, Serialize<S>>
serde1 only.Serializes the view using the provided serializer.
§Example
use shipyard::{AllStoragesViewMut, Component, View, World};
#[derive(Component, serde::Serialize)]
struct Name(String);
let world = World::new();
let mut all_storages = world.borrow::<AllStoragesViewMut>().unwrap();
let eid1 = all_storages.add_entity(Name("Alice".to_string()));
let mut serialized = Vec::new();
all_storages
.serialize::<_, View<Name>>(&mut serde_json::ser::Serializer::new(&mut serialized))
.unwrap_or_else(|_| panic!());
let serialized_str = String::from_utf8(serialized).unwrap();
assert_eq!(serialized_str, r#"[[{"index":0,"gen":0},"Alice"]]"#);Sourcepub fn deserialize<'a, 'de, D: Deserializer<'de>, V: Borrow>(
&'a self,
deserializer: D,
) -> Result<(), Deserialize<'de, D>>where
V::View<'a>: Deserialize<'de>,
Available on crate feature serde1 only.
pub fn deserialize<'a, 'de, D: Deserializer<'de>, V: Borrow>(
&'a self,
deserializer: D,
) -> Result<(), Deserialize<'de, D>>where
V::View<'a>: Deserialize<'de>,
serde1 only.Deserializes the view using the provided deserializer.
§Example
use shipyard::{AllStoragesViewMut, Component, EntityId, ViewMut, World};
#[derive(Component, serde::Deserialize)]
struct Name(String);
let world = World::new();
let mut all_storages = world.borrow::<AllStoragesViewMut>().unwrap();
let mut serialized = r#"[[{"index":0,"gen":0},"Alice"]]"#;
all_storages
.deserialize::<_, ViewMut<Name>>(&mut serde_json::de::Deserializer::from_str(serialized))
.unwrap_or_else(|_| panic!());
let alice_eid = EntityId::new_from_index_and_gen(0, 0);
assert_eq!(all_storages.get::<&Name>(alice_eid).unwrap().0, "Alice");
// Careful here, the World is not in a stable state
assert_eq!(all_storages.is_entity_alive(alice_eid), false);
// We can use World::spawn for example to fix the problem
// another solution would be to serialize EntitiesViewMut
all_storages.spawn(alice_eid);
assert_eq!(all_storages.is_entity_alive(alice_eid), true);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