Skip to content

Commit

Permalink
Merge pull request #36 from LukasKalbertodt/no-std-compat
Browse files Browse the repository at this point in the history
Use `no-std-compat` crate to simplify code
  • Loading branch information
LukasKalbertodt authored Aug 24, 2019
2 parents 615576a + 5e9fb2c commit cd2e744
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 26 deletions.
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ members = ["asm-test"]
[features]
nightly-bench = ["criterion/real_blackbox"]

[dependencies]
no-std-compat = { version = "0.2.0", features = ["alloc"] }

[dev-dependencies]
quickcheck = "0.8"
quickcheck_macros = "0.8"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ A `Vec<T>`-like collection which guarantees stable indices and features O(1) ele
It is semantically very similar to `Vec<Option<T>>`, but with a more optimized memory layout and a more convenient API.
This data structure is very useful as a foundation to implement other data structures like graphs and polygon meshes.
In those situations, `stable-vec` functions a bit like an arena memory allocator.
This crate has no dependencies and works in `#![no_std]` context (it needs the `alloc` crate, though).
This crate works in `#![no_std]` context (it needs the `alloc` crate, though).

This crate implements different strategies to store the information.
As these strategies have slightly different performance characteristics, the user can choose which to use.
Expand Down
2 changes: 1 addition & 1 deletion src/core/bitvec.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::std::{
use std::{
alloc::{alloc, alloc_zeroed, dealloc, handle_alloc_error, realloc, Layout},
fmt,
mem::{align_of, size_of},
Expand Down
2 changes: 1 addition & 1 deletion src/core/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
//! implementation, making the stable vector work. See [`Core`][core::Core] for
//! more information.
use crate::std::{
use std::{
prelude::v1::*,
fmt,
marker::PhantomData,
Expand Down
2 changes: 1 addition & 1 deletion src/core/option.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::std::{
use std::{
prelude::v1::*,
fmt,
hint::unreachable_unchecked,
Expand Down
2 changes: 1 addition & 1 deletion src/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//!
//! This is in its own module to not pollute the top-level namespace.
use crate::std::{
use std::{
iter::FusedIterator,
ops::Range,
};
Expand Down
26 changes: 5 additions & 21 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,38 +98,22 @@
#![deny(intra_doc_link_resolution_failure)]

// ----- Deal with `no_std` stuff --------------------------------------------
// Ideally we could use the crate `no-std-compat` for this. Unfortunately, it
// is only usable on nightly at the moment. Once that changes, all of this will
// be replaced.

#![no_std]

// Import the real `std` for tests.
#[cfg(test)]
#[macro_use]
extern crate std;

// Otherwise import `core` and `alloc` and define a module `std` which
// simulates the real `std` by reexporting the symbols from `core` and `alloc`.
// Well, not perfectly, but all parts we need.
#[cfg(not(test))] extern crate alloc as _alloc;
#[cfg(not(test))] extern crate core as _core;
// When compiling in a normal way, we use this compatibility layer that
// reexports symbols from `core` and `alloc` under the name `std`. This is just
// convenience so that all other imports in this crate can just use `std`.
#[cfg(not(test))]
mod std {
pub use _core::*;
pub use _alloc::alloc;

pub mod prelude {
pub mod v1 {
pub use _core::prelude::v1::*;
pub use _alloc::vec::Vec;
}
}
}
extern crate no_std_compat as std;
// ---------------------------------------------------------------------------


use crate::std::{
use std::{
prelude::v1::*,
cmp,
fmt,
Expand Down

0 comments on commit cd2e744

Please sign in to comment.