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.
This commit is contained in:
Chris Beck
2019-09-05 14:00:23 -07:00
committed by Carl Lerche
parent 73426dfaa3
commit c17e40115f
14 changed files with 77 additions and 25 deletions
+14 -2
View File
@@ -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)
}