diff options
author | 2019-09-05 14:00:23 -0700 | |
---|---|---|
committer | 2019-09-05 14:00:23 -0700 | |
commit | c17e40115f5bb2a2db71ed90dceae6ec643dc024 (patch) | |
tree | 5457d4a726f8e16120c02976fa8b07caf07df0f1 /src/bytes.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/bytes.rs')
-rw-r--r-- | src/bytes.rs | 27 |
1 files changed, 14 insertions, 13 deletions
diff --git a/src/bytes.rs b/src/bytes.rs index 1d5583b..f48609a 100644 --- a/src/bytes.rs +++ b/src/bytes.rs @@ -2,12 +2,13 @@ use crate::{Buf, BufMut}; use crate::buf::IntoIter; use crate::debug; -use std::{cmp, fmt, mem, hash, slice, ptr, usize}; -use std::borrow::{Borrow, BorrowMut}; -use std::ops::{Deref, DerefMut, RangeBounds}; -use std::sync::atomic::{self, AtomicUsize, AtomicPtr}; -use std::sync::atomic::Ordering::{Relaxed, Acquire, Release, AcqRel}; -use std::iter::{FromIterator, Iterator}; +use core::{cmp, fmt, mem, hash, slice, ptr, usize}; +use core::ops::{Deref, DerefMut, RangeBounds}; +use core::sync::atomic::{self, AtomicUsize, AtomicPtr}; +use core::sync::atomic::Ordering::{Relaxed, Acquire, Release, AcqRel}; +use core::iter::{FromIterator, Iterator}; + +use alloc::{vec::Vec, string::String, boxed::Box, borrow::{Borrow, BorrowMut}}; /// A reference counted contiguous slice of memory. /// @@ -316,10 +317,10 @@ struct Inner { } // Thread-safe reference-counted container for the shared storage. This mostly -// the same as `std::sync::Arc` but without the weak counter. The ref counting +// the same as `core::sync::Arc` but without the weak counter. The ref counting // fns are based on the ones found in `std`. // -// The main reason to use `Shared` instead of `std::sync::Arc` is that it ends +// The main reason to use `Shared` instead of `core::sync::Arc` is that it ends // up making the overall code simpler and easier to reason about. This is due to // some of the logic around setting `Inner::arc` and other ways the `arc` field // is used. Using `Arc` ended up requiring a number of funky transmutes and @@ -527,7 +528,7 @@ impl Bytes { /// Requires that `begin <= end` and `end <= self.len()`, otherwise slicing /// will panic. pub fn slice(&self, range: impl RangeBounds<usize>) -> Bytes { - use std::ops::Bound; + use core::ops::Bound; let len = self.len(); @@ -857,7 +858,7 @@ impl Bytes { /// assert_eq!(iter.next().map(|b| *b), Some(b'c')); /// assert_eq!(iter.next(), None); /// ``` - pub fn iter<'a>(&'a self) -> std::slice::Iter<'a, u8> { + pub fn iter<'a>(&'a self) -> core::slice::Iter<'a, u8> { self.bytes().iter() } } @@ -1031,7 +1032,7 @@ impl IntoIterator for Bytes { impl<'a> IntoIterator for &'a Bytes { type Item = &'a u8; - type IntoIter = std::slice::Iter<'a, u8>; + type IntoIter = core::slice::Iter<'a, u8>; fn into_iter(self) -> Self::IntoIter { self.as_ref().into_iter() @@ -1539,7 +1540,7 @@ impl BytesMut { /// assert_eq!(iter.next().map(|b| *b), Some(b'c')); /// assert_eq!(iter.next(), None); /// ``` - pub fn iter<'a>(&'a self) -> std::slice::Iter<'a, u8> { + pub fn iter<'a>(&'a self) -> core::slice::Iter<'a, u8> { self.bytes().iter() } } @@ -1780,7 +1781,7 @@ impl IntoIterator for BytesMut { impl<'a> IntoIterator for &'a BytesMut { type Item = &'a u8; - type IntoIter = std::slice::Iter<'a, u8>; + type IntoIter = core::slice::Iter<'a, u8>; fn into_iter(self) -> Self::IntoIter { self.as_ref().into_iter() |