Skip to content

Commit

Permalink
add panic feature
Browse files Browse the repository at this point in the history
fix #80
  • Loading branch information
leudz committed May 5, 2020
1 parent 98085c0 commit 934896e
Show file tree
Hide file tree
Showing 35 changed files with 2,975 additions and 2,289 deletions.
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,12 @@ parking_lot = { version = "^0.10" }
hashbrown = "^0.7"

[features]
default = ["parallel"]
default = ["panic", "parallel"]
parallel = ["rayon", "num_cpus", "std"]
non_send = ["std"]
non_sync = ["std"]
std = []
panic = []

[dev-dependencies]
serde_json = "^1"
Expand Down
2 changes: 1 addition & 1 deletion demo/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ gloo-events = "0.1.1"
awsm_web = { version = "0.1.9", features = ["tick", "webgl", "loaders", "audio"], default-features = false }
wee_alloc = { version = "0.4.5", optional = true }
wasm-logger = { version = "0.2.0", optional = true }
shipyard = { path = "../", features = ["non_send", "non_sync"], default-features = false }
shipyard = { path = "../", features = ["non_send", "non_sync", "panic"], default-features = false }
cfg-if = "0.1.10"
log = "0.4.8"
lazy_static = "1.4.0"
Expand Down
3 changes: 3 additions & 0 deletions src/delete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ pub trait Delete<T> {
/// },
/// );
/// ```
#[cfg(feature = "panic")]
#[cfg_attr(docsrs, doc(cfg(feature = "panic")))]
fn delete(self, entity: EntityId);
}

Expand Down Expand Up @@ -91,6 +93,7 @@ macro_rules! impl_delete {

Ok(())
}
#[cfg(feature = "panic")]
fn delete(self, entity: EntityId) {
Delete::<($($type,)+)>::try_delete(self, entity).unwrap()
}
Expand Down
2 changes: 1 addition & 1 deletion src/iter/abstract_mut.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ macro_rules! window {
self.dense_ptr()
}
unsafe fn id_at(&self, index: usize) -> EntityId {
<Window<'_, T>>::id_at(self, index)
<Window<'_, T>>::try_id_at(self, index).unwrap()
}
fn index_of(&self, entity: EntityId) -> Option<usize> {
(*self).index_of(entity)
Expand Down
3 changes: 3 additions & 0 deletions src/pack/loose.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ pub trait LoosePack<T> {
/// LoosePack::<(u32,)>::loose_pack((&mut u32s, &mut usizes));
/// });
/// ```
#[cfg(feature = "panic")]
#[cfg_attr(docsrs, doc(cfg(feature = "panic")))]
fn loose_pack(self);
}

Expand Down Expand Up @@ -109,6 +111,7 @@ macro_rules! impl_loose_pack {

Ok(())
}
#[cfg(feature = "panic")]
fn loose_pack(self) {
LoosePack::<($($tight,)+)>::try_loose_pack(self).unwrap()
}
Expand Down
8 changes: 6 additions & 2 deletions src/pack/tight.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ pub trait TightPack {
/// .borrow::<(ViewMut<usize>, ViewMut<u32>)>()
/// .tight_pack();
/// ```
#[cfg(feature = "panic")]
#[cfg_attr(docsrs, doc(cfg(feature = "panic")))]
fn tight_pack(self);
}

Expand Down Expand Up @@ -102,15 +104,17 @@ macro_rules! impl_tight_pack {

Ok(())
}
fn tight_pack(self) {
#[cfg(feature = "panic")]
fn tight_pack(self) {
self.try_tight_pack().unwrap()
}
}
impl<$($type: 'static),+> TightPack for ($(ViewMut<'_, $type>,)+) {
fn try_tight_pack(mut self) -> Result<(), error::Pack> {
($(&mut self.$index,)+).try_tight_pack()
}
fn tight_pack(self) {
#[cfg(feature = "panic")]
fn tight_pack(self) {
self.try_tight_pack().unwrap()
}
}
Expand Down
3 changes: 3 additions & 0 deletions src/remove.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ pub trait Remove<T: Removable> {
/// assert_eq!(old, (Some(0),));
/// });
/// ```
#[cfg(feature = "panic")]
#[cfg_attr(docsrs, doc(cfg(feature = "panic")))]
fn remove(self, entity: EntityId) -> T::Out;
}

Expand Down Expand Up @@ -140,6 +142,7 @@ macro_rules! impl_remove {
self.$index.actual_remove(entity),
)+))
}
#[cfg(feature = "panic")]
fn remove(self, entity: EntityId) -> <($($type,)+) as Removable>::Out {
Remove::<($($type,)+)>::try_remove(self, entity).unwrap()
}
Expand Down
34 changes: 34 additions & 0 deletions src/sparse_set/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@ impl<T> SparseSet<T> {
}
/// Removes `entity`'s component from this storage.
/// Unwraps errors.
#[cfg(feature = "panic")]
#[cfg_attr(docsrs, doc(cfg(feature = "panic")))]
pub fn remove(&mut self, entity: EntityId) -> Option<T>
where
T: 'static,
Expand Down Expand Up @@ -310,6 +312,8 @@ impl<T> SparseSet<T> {
}
/// Deletes `entity`'s component from this storage.
/// Unwraps errors.
#[cfg(feature = "panic")]
#[cfg_attr(docsrs, doc(cfg(feature = "panic")))]
pub fn delete(&mut self, entity: EntityId)
where
T: 'static,
Expand Down Expand Up @@ -423,6 +427,8 @@ impl<T> SparseSet<T> {
}
/// Returns the *inserted* section of an update packed window.
/// Unwraps errors.
#[cfg(feature = "panic")]
#[cfg_attr(docsrs, doc(cfg(feature = "panic")))]
pub fn inserted(&self) -> Window<'_, T> {
self.try_inserted().unwrap()
}
Expand All @@ -437,6 +443,8 @@ impl<T> SparseSet<T> {
}
/// Returns the *inserted* section of an update packed window mutably.
/// Unwraps errors.
#[cfg(feature = "panic")]
#[cfg_attr(docsrs, doc(cfg(feature = "panic")))]
pub fn inserted_mut(&mut self) -> WindowMut<'_, T> {
self.try_inserted_mut().unwrap()
}
Expand All @@ -453,6 +461,8 @@ impl<T> SparseSet<T> {
}
/// Returns the *modified* section of an update packed window.
/// Unwraps errors.
#[cfg(feature = "panic")]
#[cfg_attr(docsrs, doc(cfg(feature = "panic")))]
pub fn modified(&self) -> Window<'_, T> {
self.try_modified().unwrap()
}
Expand All @@ -467,6 +477,8 @@ impl<T> SparseSet<T> {
}
/// Returns the *modified* section of an update packed window mutably.
/// Unwraps errors.
#[cfg(feature = "panic")]
#[cfg_attr(docsrs, doc(cfg(feature = "panic")))]
pub fn modified_mut(&mut self) -> WindowMut<'_, T> {
self.try_modified_mut().unwrap()
}
Expand All @@ -480,6 +492,8 @@ impl<T> SparseSet<T> {
}
/// Returns the *inserted* and *modified* section of an update packed window.
/// Unwraps errors.
#[cfg(feature = "panic")]
#[cfg_attr(docsrs, doc(cfg(feature = "panic")))]
pub fn inserted_or_modified(&self) -> Window<'_, T> {
self.try_inserted_or_modified().unwrap()
}
Expand All @@ -496,6 +510,8 @@ impl<T> SparseSet<T> {
}
/// Returns the *inserted* and *modified* section of an update packed window mutably.
/// Unwraps errors.
#[cfg(feature = "panic")]
#[cfg_attr(docsrs, doc(cfg(feature = "panic")))]
pub fn inserted_or_modified_mut(&mut self) -> WindowMut<'_, T> {
self.try_inserted_or_modified_mut().unwrap()
}
Expand All @@ -509,6 +525,8 @@ impl<T> SparseSet<T> {
}
/// Returns the *deleted* components of an update packed window.
/// Unwraps errors.
#[cfg(feature = "panic")]
#[cfg_attr(docsrs, doc(cfg(feature = "panic")))]
pub fn deleted(&self) -> &[(EntityId, T)] {
self.try_deleted().unwrap()
}
Expand All @@ -518,6 +536,8 @@ impl<T> SparseSet<T> {
}
/// Takes ownership of the *deleted* components of an update packed window.
/// Unwraps errors.
#[cfg(feature = "panic")]
#[cfg_attr(docsrs, doc(cfg(feature = "panic")))]
pub fn take_deleted(&mut self) -> Vec<(EntityId, T)> {
self.try_take_deleted().unwrap()
}
Expand All @@ -527,6 +547,8 @@ impl<T> SparseSet<T> {
}
/// Moves all component in the *inserted* section of an update packed window to the *neutral* section.
/// Unwraps errors.
#[cfg(feature = "panic")]
#[cfg_attr(docsrs, doc(cfg(feature = "panic")))]
pub fn clear_inserted(&mut self) {
self.try_clear_inserted().unwrap()
}
Expand All @@ -536,6 +558,8 @@ impl<T> SparseSet<T> {
}
/// Moves all component in the *modified* section of an update packed window to the *neutral* section.
/// Unwraps errors.
#[cfg(feature = "panic")]
#[cfg_attr(docsrs, doc(cfg(feature = "panic")))]
pub fn clear_modified(&mut self) {
self.try_clear_modified().unwrap()
}
Expand All @@ -545,6 +569,8 @@ impl<T> SparseSet<T> {
}
/// Moves all component in the *inserted* and *modified* section of an update packed window to the *neutral* section.
/// Unwraps errors.
#[cfg(feature = "panic")]
#[cfg_attr(docsrs, doc(cfg(feature = "panic")))]
pub fn clear_inserted_and_modified(&mut self) {
self.try_clear_inserted_and_modified().unwrap()
}
Expand Down Expand Up @@ -637,6 +663,8 @@ impl<T> SparseSet<T> {
}
/// Update packs this storage making it track *inserted*, *modified* and *deleted* components.
/// Unwraps errors.
#[cfg(feature = "panic")]
#[cfg_attr(docsrs, doc(cfg(feature = "panic")))]
pub fn update_pack(&mut self)
where
T: 'static,
Expand Down Expand Up @@ -670,6 +698,8 @@ impl<T> SparseSet<T> {
}
/// Returns the `EntityId` at a given `index`.
/// Unwraps errors.
#[cfg(feature = "panic")]
#[cfg_attr(docsrs, doc(cfg(feature = "panic")))]
pub fn id_at(&self, index: usize) -> EntityId {
self.try_id_at(index).unwrap()
}
Expand Down Expand Up @@ -731,6 +761,8 @@ impl<T> SparseSet<T> {
}
/// Returns a window over `range`.
/// Unwraps errors.
#[cfg(feature = "panic")]
#[cfg_attr(docsrs, doc(cfg(feature = "panic")))]
pub fn as_window<R: core::ops::RangeBounds<usize>>(&self, range: R) -> Window<'_, T> {
self.try_as_window(range).unwrap()
}
Expand Down Expand Up @@ -766,6 +798,8 @@ impl<T> SparseSet<T> {
}
/// Returns a mutable window over `range`.
/// Unwraps errors.
#[cfg(feature = "panic")]
#[cfg_attr(docsrs, doc(cfg(feature = "panic")))]
pub fn as_window_mut<R: core::ops::RangeBounds<usize>>(
&mut self,
range: R,
Expand Down
Loading

0 comments on commit 934896e

Please sign in to comment.