Skip to content
Merged
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ script:
- cargo check --all --tests
- cargo build --all
- cargo test --all --exclude uint --exclude fixed-hash
- if [ "$TRAVIS_RUST_VERSION" == "nightly" ]; then cd parity-bytes/ && cargo build --no-default-features && cd ..;
fi
- cd fixed-hash/ && cargo test --all-features && cd ..
- cd uint/ && cargo test --features=std,quickcheck --release && cd ..
- cd plain_hasher/ && cargo test --no-default-features && cd ..
Expand Down
5 changes: 5 additions & 0 deletions parity-bytes/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,8 @@ description = "byte utilities for Parity"
license = "GPL-3.0"

[dependencies]


[features]
default = ["std"]
std = []
11 changes: 11 additions & 0 deletions parity-bytes/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
## `no_std` support

This crate has a feature, `std`, that is enabled by default. To use this crate
in a `no_std` context, add the following to your `Cargo.toml` (still requires allocator though):

```toml
[dependencies]
parity-bytes = { version = "0.1", default-features = false }
```

Until allocator api is stabilized, this type of use is limited to nightly Rust.
27 changes: 24 additions & 3 deletions parity-bytes/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,30 @@
//! Includes a pretty-printer for bytes, in the form of `ToPretty` and `PrettySlice`
//! as

use std::fmt;
use std::cmp::min;
use std::ops::{Deref, DerefMut};
#![cfg_attr(not(feature = "std"), no_std)]
#![cfg_attr(not(feature = "std"), feature(alloc))]
Comment thread
ordian marked this conversation as resolved.

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

#[cfg(feature = "std")]
extern crate core;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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


use core::{
cmp::min,
fmt,
ops::{Deref, DerefMut},
};

#[cfg(not(feature = "std"))]
use alloc::vec::Vec;

#[cfg(feature = "std")]
use std::vec::Vec;

#[cfg(not(feature = "std"))]
use alloc::string::String;

/// Slice pretty print helper
pub struct PrettySlice<'a> (&'a [u8]);
Expand Down