diff --git a/.travis.yml b/.travis.yml index 2e42d7bc0..71c988994 100644 --- a/.travis.yml +++ b/.travis.yml @@ -40,6 +40,25 @@ matrix: - env: EXTRA_ARGS="--no-default-features" script: cargo build $EXTRA_ARGS + # Ensure crate compiles with "nightly" feature (i.e. for allocation w\ no_std) + - env: EXTRA_ARGS="--no-default-features --features nightly" + script: cargo build $EXTRA_ARGS + rust: nightly + + # Ensure crate compiles with both "std" and "nightly" features + - env: EXTRA_ARGS="--no-default-features --features std,nightly" + script: cargo build $EXTRA_ARGS + rust: nightly + + # Allow "nightly" feature to fail (so we aren't blocked on upstream nightly changes) + allow_failures: + - env: EXTRA_ARGS="--no-default-features --features nightly" + script: cargo build $EXTRA_ARGS + rust: nightly + - env: EXTRA_ARGS="--no-default-features --features std,nightly" + script: cargo build $EXTRA_ARGS + rust: nightly + before_install: set -e install: diff --git a/Cargo.toml b/Cargo.toml index 3ba39de57..2b755a99b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -33,4 +33,5 @@ serde_test = "1.0" [features] default = ["std"] +nightly = [] std = ["iovec"] diff --git a/src/buf/buf.rs b/src/buf/buf.rs index 6b9ae457c..dacf507b3 100644 --- a/src/buf/buf.rs +++ b/src/buf/buf.rs @@ -1,11 +1,13 @@ use super::{IntoBuf, Take, Reader, Iter, Chain}; -#[cfg(feature = "std")] +#[cfg(any(feature = "std", feature = "nightly"))] use super::FromBuf; use byteorder::ByteOrder; #[cfg(feature = "std")] use iovec::IoVec; +#[cfg(feature = "nightly")] +use alloc::boxed::Box; use core::{cmp, ptr}; #[cfg(feature = "std")] @@ -528,7 +530,7 @@ pub trait Buf { /// /// assert_eq!(vec, &b"hello world"[..]); /// ``` - #[cfg(feature = "std")] + #[cfg(any(feature = "std", feature = "nightly"))] fn collect(self) -> B where Self: Sized, B: FromBuf, @@ -681,7 +683,7 @@ impl<'a, T: Buf + ?Sized> Buf for &'a mut T { } } -#[cfg(feature = "std")] +#[cfg(any(feature = "std", feature = "nightly"))] impl Buf for Box { fn remaining(&self) -> usize { (**self).remaining() diff --git a/src/buf/buf_mut.rs b/src/buf/buf_mut.rs index c480be823..408ded89f 100644 --- a/src/buf/buf_mut.rs +++ b/src/buf/buf_mut.rs @@ -1,8 +1,13 @@ use super::{IntoBuf, Writer}; use byteorder::ByteOrder; + #[cfg(feature = "std")] use iovec::IoVec; +#[cfg(feature = "nightly")] +use alloc::boxed::Box; +#[cfg(feature = "nightly")] +use alloc::vec::Vec; use core::{cmp, ptr, usize}; #[cfg(feature = "std")] @@ -660,7 +665,7 @@ impl<'a, T: BufMut + ?Sized> BufMut for &'a mut T { } } -#[cfg(feature = "std")] +#[cfg(any(feature = "std", feature = "nightly"))] impl BufMut for Box { fn remaining_mut(&self) -> usize { (**self).remaining_mut() @@ -709,7 +714,7 @@ impl + AsRef<[u8]>> BufMut for io::Cursor { } } -#[cfg(feature = "std")] +#[cfg(any(feature = "std", feature = "nightly"))] impl BufMut for Vec { #[inline] fn remaining_mut(&self) -> usize { diff --git a/src/buf/from_buf.rs b/src/buf/from_buf.rs index 55f5cef31..feaa169a9 100644 --- a/src/buf/from_buf.rs +++ b/src/buf/from_buf.rs @@ -1,5 +1,8 @@ use {Buf, BufMut, IntoBuf, Bytes, BytesMut}; +#[cfg(feature = "nightly")] +use alloc::vec::Vec; + /// Conversion from a [`Buf`] /// /// Implementing `FromBuf` for a type defines how it is created from a buffer. diff --git a/src/buf/mod.rs b/src/buf/mod.rs index 335f51962..82c77e278 100644 --- a/src/buf/mod.rs +++ b/src/buf/mod.rs @@ -18,7 +18,7 @@ mod buf; mod buf_mut; -#[cfg(feature = "std")] +#[cfg(any(feature = "std", feature = "nightly"))] mod from_buf; mod chain; mod into_buf; @@ -29,7 +29,7 @@ mod writer; pub use self::buf::Buf; pub use self::buf_mut::BufMut; -#[cfg(feature = "std")] +#[cfg(any(feature = "std", feature = "nightly"))] pub use self::from_buf::FromBuf; pub use self::chain::Chain; pub use self::into_buf::IntoBuf; diff --git a/src/bytes.rs b/src/bytes.rs index 3af3a74a8..472c9540d 100644 --- a/src/bytes.rs +++ b/src/bytes.rs @@ -1,4 +1,7 @@ -use {IntoBuf, Buf, BufMut}; +#[cfg(feature = "std")] +use {IntoBuf, Buf}; +use BufMut; +#[cfg(feature = "std")] use buf::Iter; use debug; @@ -7,6 +10,13 @@ use core::borrow::Borrow; use core::sync::atomic::{self, AtomicUsize, AtomicPtr}; use core::sync::atomic::Ordering::{Relaxed, Acquire, Release, AcqRel}; +#[cfg(feature = "nightly")] +use alloc::boxed::Box; +#[cfg(feature = "nightly")] +use alloc::string::String; +#[cfg(feature = "nightly")] +use alloc::vec::Vec; + #[cfg(feature = "std")] use std::io; @@ -768,6 +778,7 @@ impl Bytes { } } +#[cfg(feature = "std")] impl IntoBuf for Bytes { type Buf = io::Cursor; @@ -776,6 +787,7 @@ impl IntoBuf for Bytes { } } +#[cfg(feature = "std")] impl<'a> IntoBuf for &'a Bytes { type Buf = io::Cursor; @@ -886,6 +898,7 @@ impl Borrow<[u8]> for Bytes { } } +#[cfg(feature = "std")] impl IntoIterator for Bytes { type Item = u8; type IntoIter = Iter>; @@ -895,6 +908,7 @@ impl IntoIterator for Bytes { } } +#[cfg(feature = "std")] impl<'a> IntoIterator for &'a Bytes { type Item = u8; type IntoIter = Iter>; @@ -1376,6 +1390,7 @@ impl BufMut for BytesMut { } } +#[cfg(feature = "std")] impl IntoBuf for BytesMut { type Buf = io::Cursor; @@ -1384,6 +1399,7 @@ impl IntoBuf for BytesMut { } } +#[cfg(feature = "std")] impl<'a> IntoBuf for &'a BytesMut { type Buf = io::Cursor<&'a BytesMut>; @@ -1546,6 +1562,7 @@ impl Clone for BytesMut { } } +#[cfg(feature = "std")] impl IntoIterator for BytesMut { type Item = u8; type IntoIter = Iter>; @@ -1555,6 +1572,7 @@ impl IntoIterator for BytesMut { } } +#[cfg(feature = "std")] impl<'a> IntoIterator for &'a BytesMut { type Item = u8; type IntoIter = Iter>; diff --git a/src/lib.rs b/src/lib.rs index 8227e8011..eaecb69d3 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -71,9 +71,12 @@ #![deny(warnings, missing_docs, missing_debug_implementations)] #![doc(html_root_url = "https://docs.rs/bytes/0.4")] #![cfg_attr(not(feature = "std"), no_std)] +#![cfg_attr(feature = "nightly", feature(alloc))] extern crate byteorder; +#[cfg(feature = "nightly")] +extern crate alloc; #[cfg(feature = "std")] extern crate core; #[cfg(feature = "std")] @@ -93,12 +96,12 @@ pub use buf::{ Take, }; -#[cfg(feature = "std")] +#[cfg(any(feature = "std", feature = "nightly"))] mod bytes; -#[cfg(feature = "std")] +#[cfg(any(feature = "std", feature = "nightly"))] mod debug; -#[cfg(feature = "std")] +#[cfg(any(feature = "std", feature = "nightly"))] pub use bytes::{Bytes, BytesMut}; pub use byteorder::{ByteOrder, BigEndian, LittleEndian};