diff options
author | 2019-09-05 14:00:23 -0700 | |
---|---|---|
committer | 2019-09-05 14:00:23 -0700 | |
commit | c17e40115f5bb2a2db71ed90dceae6ec643dc024 (patch) | |
tree | 5457d4a726f8e16120c02976fa8b07caf07df0f1 /src/buf/buf_impl.rs | |
parent | 73426dfaa3e56884977d7822b79696ac2cc96a42 (diff) | |
download | bytes-c17e40115f5bb2a2db71ed90dceae6ec643dc024.tar.gz bytes-c17e40115f5bb2a2db71ed90dceae6ec643dc024.tar.zst bytes-c17e40115f5bb2a2db71ed90dceae6ec643dc024.zip |
Add no_std support, by adding an `std` feature (#281)
To make the library work as `no_std` we add an `std` feature which
is on by default. When it is off, we compile as `no_std` and make
parts of the API that require `std::io` conditional on the `std`
feature.
Diffstat (limited to 'src/buf/buf_impl.rs')
-rw-r--r-- | src/buf/buf_impl.rs | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/src/buf/buf_impl.rs b/src/buf/buf_impl.rs index e126bb4..b9e9141 100644 --- a/src/buf/buf_impl.rs +++ b/src/buf/buf_impl.rs @@ -1,6 +1,14 @@ -use super::{Take, Reader, Chain}; +use super::{Take, Chain}; -use std::{cmp, io::IoSlice, ptr, mem}; +#[cfg(feature = "std")] +use super::Reader; + +use core::{cmp, ptr, mem}; + +#[cfg(feature = "std")] +use std::io::IoSlice; + +use alloc::{boxed::Box}; macro_rules! buf_get_impl { ($this:ident, $typ:tt::$conv:tt) => ({ @@ -148,6 +156,7 @@ pub trait Buf { /// with `dst` being a zero length slice. /// /// [`writev`]: http://man7.org/linux/man-pages/man2/readv.2.html + #[cfg(feature = "std")] fn bytes_vectored<'a>(&'a self, dst: &mut [IoSlice<'a>]) -> usize { if dst.is_empty() { return 0; @@ -884,6 +893,7 @@ pub trait Buf { /// assert_eq!(11, num); /// assert_eq!(&dst[..11], &b"hello world"[..]); /// ``` + #[cfg(feature = "std")] fn reader(self) -> Reader<Self> where Self: Sized { super::reader::new(self) } @@ -915,6 +925,7 @@ impl<T: Buf + ?Sized> Buf for &mut T { (**self).bytes() } + #[cfg(feature = "std")] fn bytes_vectored<'b>(&'b self, dst: &mut [IoSlice<'b>]) -> usize { (**self).bytes_vectored(dst) } @@ -933,6 +944,7 @@ impl<T: Buf + ?Sized> Buf for Box<T> { (**self).bytes() } + #[cfg(feature = "std")] fn bytes_vectored<'b>(&'b self, dst: &mut [IoSlice<'b>]) -> usize { (**self).bytes_vectored(dst) } |