Skip to content

Enable use from no_std crates #92

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ bench = false

[dependencies]
serde = { version = "1.0", optional = true }
hashmap_core = { version = "0.1.10", optional = true }

[dev-dependencies]
itertools = "0.7.0" # 0.8 not compiles on Rust 1.18
Expand All @@ -39,6 +40,10 @@ lazy_static = "1"
serde_test = "1.0.5"

[features]
default = ["std"]
std = []
core = ["hashmap_core"]

# Serialization with serde 1.0
serde-1 = ["serde"]

Expand Down
28 changes: 28 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,34 @@
//! upgrade policy, where in a later 1.x version, we will raise the minimum
//! required Rust version.

#![cfg_attr(not(feature = "std"), no_std)]

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

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

#[cfg(not(feature = "std"))]
mod std {
pub use core::*;

pub mod vec {
pub use alloc::vec::*;
}

pub mod boxed {
pub use alloc::boxed::*;
}

pub mod collections {
pub mod hash_map {
pub use hashmap_core::map::*;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just realized this changes our default RandomState type, normally defined only in std, which is also a breaking change.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I think hashmap_core should be dropped from this PR, because it only adds this, which we don't want.

We'd like to not have a default hasher, that should work, and not have IndexMap::new() at all when we are no-std.

}
}
}

#[macro_use]
mod macros;
#[cfg(feature = "serde-1")]
Expand Down
2 changes: 2 additions & 0 deletions src/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ use std::hash::Hasher;
use std::iter::FromIterator;
use std::collections::hash_map::RandomState;
use std::ops::RangeFull;
use std::boxed::Box;
use std::vec::Vec;

use std::cmp::{max, Ordering};
use std::fmt;
Expand Down