Skip to content

Commit

Permalink
Improve no_std handling
Browse files Browse the repository at this point in the history
Stop using double negative cargo feature
This prevents accidently using items from std::prelude

https://www.reddit.com/r/rust/comments/1hs6spy/psa_for_std_feature_in_no_std_libraries
  • Loading branch information
leudz committed Jan 28, 2025
1 parent 375a8a8 commit 956acd6
Show file tree
Hide file tree
Showing 8 changed files with 13 additions and 6 deletions.
5 changes: 4 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,12 @@
#![warn(clippy::maybe_infinite_iter)]
#![allow(clippy::uninlined_format_args)]
#![allow(clippy::needless_lifetimes)]
#![cfg_attr(not(any(feature = "std", test)), no_std)]
#![cfg_attr(docsrs, feature(doc_cfg))]
#![warn(missing_docs)]
#![no_std]

#[cfg(feature = "std")]
extern crate std;

extern crate alloc;

Expand Down
1 change: 1 addition & 0 deletions src/sparse_set/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1029,6 +1029,7 @@ impl<T: 'static + Component> Storage for NonSendSync<SparseSet<T>> {
mod tests {
use super::*;
use crate::Component;
use std::println;

#[derive(PartialEq, Eq, Debug)]
struct STR(&'static str);
Expand Down
2 changes: 0 additions & 2 deletions src/sparse_set/sparse_array.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
use crate::entity_id::EntityId;
#[cfg(not(feature = "std"))]
use alloc::boxed::Box;
#[cfg(not(feature = "std"))]
use alloc::vec::Vec;
use core::hint::unreachable_unchecked;
use core::mem::size_of;
Expand Down
3 changes: 2 additions & 1 deletion src/views/unique_or_default.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ use crate::tracking::TrackingTimestamp;
use crate::views::UniqueView;
use crate::world::World;
use crate::{error, BorrowInfo};
use std::ops::Deref;
use alloc::vec::Vec;
use core::ops::Deref;

/// Shared view over a unique component storage.
///
Expand Down
3 changes: 2 additions & 1 deletion src/views/unique_or_default_mut.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ use crate::tracking::TrackingTimestamp;
use crate::views::UniqueViewMut;
use crate::world::World;
use crate::{error, BorrowInfo};
use std::ops::{Deref, DerefMut};
use alloc::vec::Vec;
use core::ops::{Deref, DerefMut};

/// Exclusive view over a unique component storage.
///
Expand Down
1 change: 1 addition & 0 deletions src/views/unique_or_init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use crate::info::TypeInfo;
use crate::tracking::TrackingTimestamp;
use crate::views::UniqueView;
use crate::world::World;
use alloc::vec::Vec;
use core::cell::OnceCell;

/// Shared view over a unique component storage.
Expand Down
1 change: 1 addition & 0 deletions src/views/unique_or_init_mut.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use crate::info::TypeInfo;
use crate::tracking::TrackingTimestamp;
use crate::views::UniqueViewMut;
use crate::world::World;
use alloc::vec::Vec;
use core::cell::OnceCell;

/// Exclusive view over a unique component storage.
Expand Down
3 changes: 2 additions & 1 deletion src/world/run_batches.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::error;
use crate::scheduler::{Batches, Label};
use crate::world::World;
use alloc::boxed::Box;

impl World {
#[cfg(feature = "parallel")]
Expand Down Expand Up @@ -50,7 +51,7 @@ impl World {
Ok(true)
}
})
.collect::<Result<Vec<_>, error::RunWorkload>>()?,
.collect::<Result<alloc::vec::Vec<_>, error::RunWorkload>>()?,
);

let mut start = 0;
Expand Down

0 comments on commit 956acd6

Please sign in to comment.