diff --git a/triehash/CHANGELOG.md b/triehash/CHANGELOG.md index 67629508f..c8b6fd2be 100644 --- a/triehash/CHANGELOG.md +++ b/triehash/CHANGELOG.md @@ -5,7 +5,7 @@ The format is based on [Keep a Changelog]. [Keep a Changelog]: http://keepachangelog.com/en/1.0.0/ ## [Unreleased] - +- Added no-std support (https://github.com/paritytech/parity-common/pull/280) ## [0.8.1] - 2019-10-24 - Migrated to 2018 edition (https://github.com/paritytech/parity-common/pull/214) ### Dependencies diff --git a/triehash/Cargo.toml b/triehash/Cargo.toml index 701aae36b..a941edaa0 100644 --- a/triehash/Cargo.toml +++ b/triehash/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "triehash" -version = "0.8.1" +version = "0.8.2" authors = ["Parity Technologies "] description = "In-memory patricia trie operations" repository = "https://github.com/paritytech/parity-common" @@ -8,8 +8,8 @@ license = "GPL-3.0" edition = "2018" [dependencies] -hash-db = "0.15.2" -rlp = { version = "0.4", path = "../rlp" } +hash-db = { version = "0.15.2", default-features = false } +rlp = { version = "0.4", path = "../rlp", default-features = false } [dev-dependencies] criterion = "0.3.0" @@ -19,6 +19,13 @@ tiny-keccak = { version = "2.0", features = ["keccak"] } trie-standardmap = "0.15.2" hex-literal = "0.2.1" +[features] +default = ["std"] +std = [ + "hash-db/std", + "rlp/std", +] + [[bench]] name = "triehash" path = "benches/triehash.rs" diff --git a/triehash/src/lib.rs b/triehash/src/lib.rs index 41b2a0d17..964e7e14f 100644 --- a/triehash/src/lib.rs +++ b/triehash/src/lib.rs @@ -18,9 +18,25 @@ //! //! This module should be used to generate trie root hash. -use std::cmp; -use std::collections::BTreeMap; -use std::iter::once; +#![cfg_attr(not(feature = "std"), no_std)] + +#[cfg(not(feature = "std"))] +extern crate alloc; + +#[cfg(feature = "std")] +mod rstd { + pub use std::collections::BTreeMap; +} + +#[cfg(not(feature = "std"))] +mod rstd { + pub use alloc::collections::BTreeMap; + pub use alloc::vec::Vec; +} + +use core::cmp; +use core::iter::once; +use rstd::*; use hash_db::Hasher; use rlp::RlpStream;