Skip to content

Commit

Permalink
Switch from lazy_static to once_cell
Browse files Browse the repository at this point in the history
Once_cell has better no_std support
  • Loading branch information
Jinxit committed Aug 3, 2022
1 parent 3f6d833 commit 9d385a0
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 10 deletions.
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ maintenance = { status = "actively-developed" }
default = ["std", "atomic"]
std = []
atomic = ["spin"]
atomic-polyfill = ["dep:atomic-polyfill"]
atomic-polyfill = ["once_cell/atomic-polyfill", "dep:atomic-polyfill"]
# Enables derive(Bundle)
macros = ["hecs-macros", "lazy_static"]
macros = ["hecs-macros", "once_cell"]
# Enables the serialize::column module
column-serialize = ["serde"]
# Enables the serialize::row module
Expand All @@ -34,7 +34,7 @@ row-serialize = ["serde"]
atomic-polyfill = { version = "0.1.7", optional = true }
hecs-macros = { path = "macros", version = "0.8.2", optional = true }
hashbrown = { version = "0.12.0", default-features = false, features = ["ahash", "inline-more"] }
lazy_static = { version = "1.4.0", optional = true, features = ["spin_no_std"] }
once_cell = { version = "1.12.0", default-features = false, optional = true, features = ["alloc"] }
serde = { version = "1.0.117", default-features = false, optional = true }
spin = { version = "0.9.2", default-features = false, optional = true, features = ["mutex", "spin_mutex"] }

Expand Down
10 changes: 4 additions & 6 deletions macros/src/bundle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,10 @@ fn gen_bundle_impl(
};
let with_static_ids_body = if generics.params.is_empty() {
quote! {
::hecs::lazy_static::lazy_static! {
static ref ELEMENTS: [::std::any::TypeId; #num_tys] = {
#with_static_ids_inner
};
}
f(&*ELEMENTS)
static ELEMENTS: ::hecs::once_cell::race::OnceBox<[::core::any::TypeId; #num_tys]> = ::hecs::once_cell::race::OnceBox::new();
f(ELEMENTS.get_or_init(||
::hecs::alloc::boxed::Box::new(#with_static_ids_inner)
))
}
} else {
quote! {
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ pub use archetype::TypeInfo;
pub use bundle::DynamicClone;
#[cfg(feature = "macros")]
#[doc(hidden)]
pub use lazy_static;
pub use once_cell;
#[doc(hidden)]
pub use query::Fetch;

Expand Down

0 comments on commit 9d385a0

Please sign in to comment.