diff --git a/Cargo.toml b/Cargo.toml index ad5693d..b45ed65 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -33,7 +33,9 @@ travis-ci = { repository = "bodil/im-rs" } version_check = "0.9" [features] +default = ["no_std"] debug = [] +no_std = ["ahash", "hashbrown"] [dependencies] typenum = "1.12" @@ -47,6 +49,8 @@ serde = { version = "1", optional = true } rayon = { version = "1", optional = true } refpool = { version = "0.4", optional = true } arbitrary = { version = "0.4", optional = true } +ahash = { version = "0.7.4", optional = true } +hashbrown = { version = "0.11.2", optional = true } [dev-dependencies] proptest = "0.10" diff --git a/rc/Cargo.toml b/rc/Cargo.toml index a3bcbf2..fd437df 100644 --- a/rc/Cargo.toml +++ b/rc/Cargo.toml @@ -25,6 +25,7 @@ travis-ci = { repository = "bodil/im-rs" } [features] pool = ["refpool", "sized-chunks/refpool"] debug = [] +no_std = ["ahash", "hashbrown"] [build-dependencies] version_check = "0.9" @@ -41,6 +42,8 @@ serde = { version = "1", optional = true } rayon = { version = "1", optional = true } refpool = { version = "0.4", optional = true } arbitrary = { version = "0.4", optional = true } +ahash = { version = "0.7.4", optional = true } +hashbrown = { version = "0.11.2", optional = true } [dev-dependencies] proptest = "0.10" diff --git a/src/fakepool.rs b/src/fakepool.rs index 5ff36f7..dd2f731 100644 --- a/src/fakepool.rs +++ b/src/fakepool.rs @@ -4,10 +4,10 @@ #![allow(dead_code)] -use std::marker::PhantomData; -use std::ops::Deref; -use std::rc::Rc as RRc; -use std::sync::Arc as RArc; +use core::marker::PhantomData; +use core::ops::Deref; +use alloc::rc::Rc as RRc; +use alloc::sync::Arc as RArc; use crate::nodes::chunk::Chunk; @@ -112,12 +112,12 @@ where impl Eq for Rc where A: Eq {} -impl std::fmt::Debug for Rc +impl core::fmt::Debug for Rc where - A: std::fmt::Debug, + A: core::fmt::Debug, { #[inline(always)] - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> Result<(), std::fmt::Error> { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> Result<(), core::fmt::Error> { self.0.fmt(f) } } @@ -197,12 +197,12 @@ where impl Eq for Arc where A: Eq {} -impl std::fmt::Debug for Arc +impl core::fmt::Debug for Arc where - A: std::fmt::Debug, + A: core::fmt::Debug, { #[inline(always)] - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> Result<(), std::fmt::Error> { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> Result<(), core::fmt::Error> { self.0.fmt(f) } } diff --git a/src/hash/map.rs b/src/hash/map.rs index 02b84ba..84556e6 100644 --- a/src/hash/map.rs +++ b/src/hash/map.rs @@ -21,15 +21,25 @@ //! [std::hash::Hash]: https://doc.rust-lang.org/std/hash/trait.Hash.html //! [std::collections::hash_map::RandomState]: https://doc.rust-lang.org/std/collections/hash_map/struct.RandomState.html -use std::borrow::Borrow; -use std::cmp::Ordering; +use core::borrow::Borrow; +use core::cmp::Ordering; +#[cfg(not(feature = "no_std"))] use std::collections; +#[cfg(feature = "no_std")] +use hashbrown as collections; +#[cfg(feature = "no_std")] +use ahash::RandomState; +#[cfg(not(feature = "no_std"))] use std::collections::hash_map::RandomState; -use std::fmt::{Debug, Error, Formatter}; -use std::hash::{BuildHasher, Hash, Hasher}; -use std::iter::{FromIterator, FusedIterator, Sum}; -use std::mem; -use std::ops::{Add, Index, IndexMut}; +use core::fmt::{Debug, Error, Formatter}; +use core::hash::{BuildHasher, Hash, Hasher}; +use core::iter::{FromIterator, FusedIterator, Sum}; +use core::mem; +use core::ops::{Add, Index, IndexMut}; +use alloc::{vec::Vec, vec}; +use alloc::borrow::ToOwned; +use alloc::string::String; +use alloc::format; use crate::nodes::hamt::{ hash_key, Drain as NodeDrain, HashBits, HashValue, Iter as NodeIter, IterMut as NodeIterMut, @@ -220,7 +230,7 @@ impl HashMap { /// /// Time: O(1) pub fn ptr_eq(&self, other: &Self) -> bool { - std::ptr::eq(self, other) || PoolRef::ptr_eq(&self.root, &other.root) + core::ptr::eq(self, other) || PoolRef::ptr_eq(&self.root, &other.root) } /// Get a reference to the memory pool used by this map. @@ -1779,7 +1789,8 @@ where S: BuildHasher, { fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error> { - let mut keys = collections::BTreeSet::new(); + #[cfg(not(feature = "no_std"))] let mut keys = collections::BTreeSet::new(); + #[cfg(feature = "no_std")] let mut keys = collections::HashSet::new(); keys.extend(self.keys()); let mut d = f.debug_map(); for key in keys { @@ -2046,6 +2057,7 @@ where } } +#[cfg(not(feature = "no_std"))] impl From> for HashMap where K: Hash + Eq + Clone, @@ -2057,6 +2069,7 @@ where } } +#[cfg(not(feature = "no_std"))] impl<'a, K, V, S> From<&'a collections::BTreeMap> for HashMap where K: Hash + Eq + Clone, @@ -2105,7 +2118,7 @@ mod test { use crate::test::LolHasher; use ::proptest::num::{i16, usize}; use ::proptest::{collection, proptest}; - use std::hash::BuildHasherDefault; + use core::hash::BuildHasherDefault; #[test] fn safe_mutation() { diff --git a/src/hash/set.rs b/src/hash/set.rs index 4f1dfee..091c0ed 100644 --- a/src/hash/set.rs +++ b/src/hash/set.rs @@ -21,15 +21,24 @@ //! [std::hash::Hash]: https://doc.rust-lang.org/std/hash/trait.Hash.html //! [std::collections::hash_map::RandomState]: https://doc.rust-lang.org/std/collections/hash_map/struct.RandomState.html -use std::borrow::Borrow; -use std::cmp::Ordering; +use core::borrow::Borrow; +use core::cmp::Ordering; +#[cfg(feature = "no_std")] +use ahash::RandomState; +#[cfg(not(feature = "no_std"))] use std::collections::hash_map::RandomState; +#[cfg(feature = "no_std")] +use hashbrown as collections; +#[cfg(not(feature = "no_std"))] use std::collections::{self, BTreeSet}; -use std::fmt::{Debug, Error, Formatter}; -use std::hash::{BuildHasher, Hash, Hasher}; -use std::iter::FusedIterator; -use std::iter::{FromIterator, IntoIterator, Sum}; -use std::ops::{Add, Deref, Mul}; +use core::fmt::{Debug, Error, Formatter}; +use core::hash::{BuildHasher, Hash, Hasher}; +use core::iter::FusedIterator; +use core::iter::{FromIterator, IntoIterator, Sum}; +use core::ops::{Add, Deref, Mul}; +use alloc::{vec::Vec, vec}; +use alloc::borrow::ToOwned; +use alloc::string::String; use crate::nodes::hamt::{hash_key, Drain as NodeDrain, HashValue, Iter as NodeIter, Node}; use crate::ordset::OrdSet; @@ -217,7 +226,7 @@ impl HashSet { /// /// Time: O(1) pub fn ptr_eq(&self, other: &Self) -> bool { - std::ptr::eq(self, other) || PoolRef::ptr_eq(&self.root, &other.root) + core::ptr::eq(self, other) || PoolRef::ptr_eq(&self.root, &other.root) } /// Get a reference to the memory pool used by this set. @@ -1015,6 +1024,7 @@ where } } +#[cfg(not(feature = "no_std"))] impl<'a, A, S> From<&'a BTreeSet> for HashSet where A: Hash + Eq + Clone, @@ -1058,12 +1068,14 @@ pub mod proptest { #[cfg(test)] mod test { + extern crate std; + use std::println; use super::proptest::*; use super::*; use crate::test::LolHasher; use ::proptest::num::i16; use ::proptest::proptest; - use std::hash::BuildHasherDefault; + use core::hash::BuildHasherDefault; #[test] fn insert_failing() { diff --git a/src/iter.rs b/src/iter.rs index 4e99559..2928dd9 100644 --- a/src/iter.rs +++ b/src/iter.rs @@ -33,7 +33,7 @@ where F: Fn(S) -> Option<(A, S)>, { let mut value = Some(value); - std::iter::from_fn(move || { + core::iter::from_fn(move || { f(value.take().unwrap()).map(|(next, state)| { value = Some(state); next diff --git a/src/lib.rs b/src/lib.rs index 0444dbd..6a81191 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -335,11 +335,16 @@ //! [b-tree]: https://en.wikipedia.org/wiki/B-tree //! [cons-list]: https://en.wikipedia.org/wiki/Cons#Lists +#![no_std] #![forbid(rust_2018_idioms)] #![deny(unsafe_code, nonstandard_style)] #![warn(unreachable_pub, missing_docs)] #![cfg_attr(has_specialisation, feature(specialization))] +extern crate alloc; +#[cfg(not(feature = "no_std"))] +extern crate std; + #[cfg(test)] #[macro_use] extern crate pretty_assertions; diff --git a/src/nodes/btree.rs b/src/nodes/btree.rs index 79a5bc1..a3a24f2 100644 --- a/src/nodes/btree.rs +++ b/src/nodes/btree.rs @@ -2,10 +2,11 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. -use std::borrow::Borrow; -use std::cmp::Ordering; -use std::mem; -use std::ops::{Bound, RangeBounds}; +use core::borrow::Borrow; +use core::cmp::Ordering; +use core::mem; +use core::ops::{Bound, RangeBounds}; +use alloc::{vec::Vec, vec}; use sized_chunks::Chunk; use typenum::{Add1, Unsigned}; @@ -1303,7 +1304,7 @@ where }, (Some(old), Some(new)) => match (old, new) { (IterItem::Consider(old), IterItem::Consider(new)) => { - if !std::ptr::eq(old, new) { + if !core::ptr::eq(old, new) { match old.keys[0].cmp_values(&new.keys[0]) { Ordering::Less => { Self::push(&mut self.old_stack, &old); diff --git a/src/nodes/hamt.rs b/src/nodes/hamt.rs index 8ee6157..f78b07c 100644 --- a/src/nodes/hamt.rs +++ b/src/nodes/hamt.rs @@ -2,12 +2,13 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. -use std::borrow::Borrow; -use std::fmt; -use std::hash::{BuildHasher, Hash, Hasher}; -use std::iter::FusedIterator; -use std::slice::{Iter as SliceIter, IterMut as SliceIterMut}; -use std::{mem, ptr}; +use core::borrow::Borrow; +use core::fmt; +use core::hash::{BuildHasher, Hash, Hasher}; +use core::iter::FusedIterator; +use core::slice::{Iter as SliceIter, IterMut as SliceIterMut}; +use core::{mem, ptr}; +use alloc::{vec::Vec, vec}; use bitmaps::Bits; use sized_chunks::sparse_chunk::{Iter as ChunkIter, IterMut as ChunkIterMut, SparseChunk}; diff --git a/src/nodes/rrb.rs b/src/nodes/rrb.rs index 2ef031a..1ab5fda 100644 --- a/src/nodes/rrb.rs +++ b/src/nodes/rrb.rs @@ -2,8 +2,10 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. -use std::mem::replace; -use std::ops::Range; +use core::mem::replace; +use core::ops::Range; +use alloc::format; +use alloc::{vec::Vec, vec}; use crate::nodes::chunk::{Chunk, CHUNK_SIZE}; use crate::util::{ diff --git a/src/ord/map.rs b/src/ord/map.rs index 14931f7..243a71b 100644 --- a/src/ord/map.rs +++ b/src/ord/map.rs @@ -17,14 +17,21 @@ //! [hashmap::HashMap]: ../hashmap/struct.HashMap.html //! [std::cmp::Ord]: https://doc.rust-lang.org/std/cmp/trait.Ord.html -use std::borrow::Borrow; -use std::cmp::Ordering; +use core::borrow::Borrow; +use core::cmp::Ordering; +#[cfg(feature = "no_std")] +use hashbrown as collections; +#[cfg(not(feature = "no_std"))] use std::collections; -use std::fmt::{Debug, Error, Formatter}; -use std::hash::{BuildHasher, Hash, Hasher}; -use std::iter::{FromIterator, Iterator, Sum}; -use std::mem; -use std::ops::{Add, Index, IndexMut, RangeBounds}; +use core::fmt::{Debug, Error, Formatter}; +use core::hash::{BuildHasher, Hash, Hasher}; +use core::iter::{FromIterator, Iterator, Sum}; +use core::mem; +use core::ops::{Add, Index, IndexMut, RangeBounds}; +use alloc::{vec::Vec, vec}; +use alloc::borrow::ToOwned; +use alloc::string::String; +use alloc::format; use crate::hashmap::HashMap; use crate::nodes::btree::{BTreeValue, Insert, Node, Remove}; @@ -251,7 +258,7 @@ impl OrdMap { /// /// Time: O(1) pub fn ptr_eq(&self, other: &Self) -> bool { - std::ptr::eq(self, other) || PoolRef::ptr_eq(&self.root, &other.root) + core::ptr::eq(self, other) || PoolRef::ptr_eq(&self.root, &other.root) } /// Get the size of a map. @@ -2117,17 +2124,17 @@ where } } -impl From> for OrdMap +impl From> for OrdMap where K: Ord + Clone + From, V: Clone + From, { - fn from(m: collections::BTreeMap) -> OrdMap { + fn from(m: alloc::collections::BTreeMap) -> OrdMap { m.into_iter().collect() } } -impl<'a, K: Ord, V, RK, RV, OK, OV> From<&'a collections::BTreeMap> for OrdMap +impl<'a, K: Ord, V, RK, RV, OK, OV> From<&'a alloc::collections::BTreeMap> for OrdMap where K: Ord + Clone + From, V: Clone + From, @@ -2136,7 +2143,7 @@ where RK: Ord + ToOwned, RV: ToOwned, { - fn from(m: &'a collections::BTreeMap) -> OrdMap { + fn from(m: &'a alloc::collections::BTreeMap) -> OrdMap { m.iter() .map(|(k, v)| (k.to_owned(), v.to_owned())) .collect() @@ -2443,7 +2450,7 @@ mod test { ref ops in collection::vec((bool::ANY, usize::ANY, usize::ANY), 1..1000) ) { let mut map = input.clone(); - let mut tree: collections::BTreeMap = input.iter().map(|(k, v)| (*k, *v)).collect(); + let mut tree: alloc::collections::BTreeMap = input.iter().map(|(k, v)| (*k, *v)).collect(); for (ins, key, val) in ops { if *ins { tree.insert(*key, *val); diff --git a/src/ord/set.rs b/src/ord/set.rs index 10d692b..5bf85d4 100644 --- a/src/ord/set.rs +++ b/src/ord/set.rs @@ -17,13 +17,19 @@ //! [hashset::HashSet]: ../hashset/struct.HashSet.html //! [std::cmp::Ord]: https://doc.rust-lang.org/std/cmp/trait.Ord.html -use std::borrow::Borrow; -use std::cmp::Ordering; +use core::borrow::Borrow; +use core::cmp::Ordering; +#[cfg(feature = "no_std")] +use hashbrown as collections; +#[cfg(not(feature = "no_std"))] use std::collections; -use std::fmt::{Debug, Error, Formatter}; -use std::hash::{BuildHasher, Hash, Hasher}; -use std::iter::{FromIterator, IntoIterator, Sum}; -use std::ops::{Add, Deref, Mul, RangeBounds}; +use core::fmt::{Debug, Error, Formatter}; +use core::hash::{BuildHasher, Hash, Hasher}; +use core::iter::{FromIterator, IntoIterator, Sum}; +use core::ops::{Add, Deref, Mul, RangeBounds}; +use alloc::{vec::Vec, vec}; +use alloc::borrow::ToOwned; +use alloc::string::String; use crate::hashset::HashSet; use crate::nodes::btree::{ @@ -274,7 +280,7 @@ impl OrdSet { /// /// Time: O(1) pub fn ptr_eq(&self, other: &Self) -> bool { - std::ptr::eq(self, other) || PoolRef::ptr_eq(&self.root, &other.root) + core::ptr::eq(self, other) || PoolRef::ptr_eq(&self.root, &other.root) } /// Get a reference to the memory pool used by this set. @@ -1139,14 +1145,14 @@ impl<'a, A: Eq + Hash + Ord + Clone> From<&'a collections::HashSet> for OrdSe } } -impl From> for OrdSet { - fn from(btree_set: collections::BTreeSet) -> Self { +impl From> for OrdSet { + fn from(btree_set: alloc::collections::BTreeSet) -> Self { btree_set.into_iter().collect() } } -impl<'a, A: Ord + Clone> From<&'a collections::BTreeSet> for OrdSet { - fn from(btree_set: &collections::BTreeSet) -> Self { +impl<'a, A: Ord + Clone> From<&'a alloc::collections::BTreeSet> for OrdSet { + fn from(btree_set: &alloc::collections::BTreeSet) -> Self { btree_set.iter().cloned().collect() } } diff --git a/src/proptest.rs b/src/proptest.rs index 9180ef2..5df5b01 100644 --- a/src/proptest.rs +++ b/src/proptest.rs @@ -5,9 +5,9 @@ use crate::{HashMap, HashSet, OrdMap, OrdSet, Vector}; use ::proptest::collection::vec; use ::proptest::strategy::{BoxedStrategy, Strategy, ValueTree}; -use std::hash::Hash; -use std::iter::FromIterator; -use std::ops::Range; +use core::hash::Hash; +use core::iter::FromIterator; +use core::ops::Range; /// A strategy for generating a [`Vector`][Vector] of a certain size. /// diff --git a/src/ser.rs b/src/ser.rs index d9a35e5..f05e7a3 100644 --- a/src/ser.rs +++ b/src/ser.rs @@ -4,10 +4,13 @@ use serde::de::{Deserialize, Deserializer, MapAccess, SeqAccess, Visitor}; use serde::ser::{Serialize, SerializeMap, SerializeSeq, Serializer}; -use std::fmt; -use std::hash::{BuildHasher, Hash}; -use std::marker::PhantomData; -use std::ops::Deref; +use core::fmt; +use core::hash::{BuildHasher, Hash}; +use core::marker::PhantomData; +use core::ops::Deref; +use alloc::{vec::Vec, vec}; +use alloc::borrow::ToOwned; +use alloc::string::String; use crate::hashmap::HashMap; use crate::hashset::HashSet; diff --git a/src/sort.rs b/src/sort.rs index 6c98001..c63c034 100644 --- a/src/sort.rs +++ b/src/sort.rs @@ -4,8 +4,8 @@ use crate::vector::FocusMut; use rand_core::{RngCore, SeedableRng}; -use std::cmp::Ordering; -use std::mem; +use core::cmp::Ordering; +use core::mem; fn gen_range(rng: &mut R, min: usize, max: usize) -> usize { let range = max - min; diff --git a/src/sync.rs b/src/sync.rs index 9b13755..7c3a6b5 100644 --- a/src/sync.rs +++ b/src/sync.rs @@ -6,7 +6,7 @@ pub(crate) use self::lock::Lock; #[cfg(threadsafe)] mod lock { - use std::sync::{Arc, Mutex, MutexGuard}; + use alloc::sync::{Arc, Mutex, MutexGuard}; /// Thread safe lock: just wraps a `Mutex`. pub(crate) struct Lock { diff --git a/src/test.rs b/src/test.rs index 9887d01..3a4588d 100644 --- a/src/test.rs +++ b/src/test.rs @@ -3,8 +3,8 @@ // file, You can obtain one at http://mozilla.org/MPL/2.0/. use metrohash::MetroHash64; -use std::hash::{BuildHasher, Hasher}; -use std::marker::PhantomData; +use core::hash::{BuildHasher, Hasher}; +use core::marker::PhantomData; use typenum::{Unsigned, U64}; pub(crate) fn is_sorted(l: I) -> bool diff --git a/src/tests/hashset.rs b/src/tests/hashset.rs index 01df2be..4b175ad 100644 --- a/src/tests/hashset.rs +++ b/src/tests/hashset.rs @@ -1,24 +1,42 @@ #![allow(clippy::unit_arg)] +#[cfg(feature = "no_std")] +use hashbrown::HashSet as NatSet; +#[cfg(not(feature = "no_std"))] use std::collections::HashSet as NatSet; -use std::fmt::{Debug, Error, Formatter, Write}; -use std::hash::Hash; +use core::fmt::{Debug, Error, Formatter, Write}; +use core::hash::Hash; +use alloc::vec::Vec; +use alloc::string::String; use crate::HashSet; use proptest::proptest; +#[cfg(not(feature = "no_std"))] use proptest_derive::Arbitrary; +#[cfg(not(feature = "no_std"))] #[derive(Arbitrary, Debug)] enum Action { Insert(A), Remove(A), } +#[cfg(feature = "no_std")] +#[derive(Debug)] +enum Action { + Insert(A), + Remove(A), +} +#[cfg(not(feature = "no_std"))] #[derive(Arbitrary)] struct Actions(Vec>) where A: Hash + Eq + Clone; +#[cfg(feature = "no_std")] +struct Actions(Vec>) + where + A: Hash + Eq + Clone; impl Debug for Actions where diff --git a/src/tests/ordset.rs b/src/tests/ordset.rs index 15efec5..500dc21 100644 --- a/src/tests/ordset.rs +++ b/src/tests/ordset.rs @@ -1,7 +1,7 @@ #![allow(clippy::unit_arg)] -use std::collections::BTreeSet; -use std::fmt::{Debug, Error, Formatter, Write}; +use alloc::collections::BTreeSet; +use core::fmt::{Debug, Error, Formatter, Write}; use crate::OrdSet; diff --git a/src/tests/vector.rs b/src/tests/vector.rs index ef0ceff..3b7e2b3 100644 --- a/src/tests/vector.rs +++ b/src/tests/vector.rs @@ -1,7 +1,9 @@ #![allow(clippy::unit_arg)] -use std::fmt::{Debug, Error, Formatter, Write}; -use std::iter::FromIterator; +use core::fmt::{Debug, Error, Formatter, Write}; +use core::iter::FromIterator; +use alloc::format; +use alloc::{vec::Vec, vec}; use crate::Vector; diff --git a/src/util.rs b/src/util.rs index 5451f15..8a3fc15 100644 --- a/src/util.rs +++ b/src/util.rs @@ -4,9 +4,9 @@ // Every codebase needs a `util` module. -use std::cmp::Ordering; -use std::ops::{Bound, IndexMut, Range, RangeBounds}; -use std::ptr; +use core::cmp::Ordering; +use core::ops::{Bound, IndexMut, Range, RangeBounds}; +use core::ptr; #[cfg(feature = "pool")] pub(crate) use refpool::{PoolClone, PoolDefault}; @@ -19,7 +19,7 @@ pub(crate) use crate::fakepool::{Arc as PoolRef, Pool, PoolClone, PoolDefault}; // `Ref` == `Arc` when threadsafe #[cfg(threadsafe)] -pub(crate) type Ref = std::sync::Arc; +pub(crate) type Ref = alloc::sync::Arc; // `Rc` without refpool #[cfg(all(not(threadsafe), not(feature = "pool")))] diff --git a/src/vector/focus.rs b/src/vector/focus.rs index bf34255..8d9f4a2 100644 --- a/src/vector/focus.rs +++ b/src/vector/focus.rs @@ -2,10 +2,10 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. -use std::mem::{replace, swap}; -use std::ops::{Range, RangeBounds}; -use std::ptr::null; -use std::sync::atomic::{AtomicPtr, Ordering}; +use core::mem::{replace, swap}; +use core::ops::{Range, RangeBounds}; +use core::ptr::null; +use core::sync::atomic::{AtomicPtr, Ordering}; use crate::nodes::chunk::Chunk; use crate::sync::Lock; diff --git a/src/vector/mod.rs b/src/vector/mod.rs index 7d54de1..ee34035 100644 --- a/src/vector/mod.rs +++ b/src/vector/mod.rs @@ -43,14 +43,18 @@ //! [Vec]: https://doc.rust-lang.org/std/vec/struct.Vec.html //! [VecDeque]: https://doc.rust-lang.org/std/collections/struct.VecDeque.html -use std::borrow::Borrow; -use std::cmp::Ordering; -use std::fmt::{Debug, Error, Formatter}; -use std::hash::{Hash, Hasher}; -use std::iter::Sum; -use std::iter::{FromIterator, FusedIterator}; -use std::mem::{replace, swap}; -use std::ops::{Add, Index, IndexMut, RangeBounds}; +use core::borrow::Borrow; +use core::cmp::Ordering; +use core::fmt::{Debug, Error, Formatter}; +use core::hash::{Hash, Hasher}; +use core::iter::Sum; +use core::iter::{FromIterator, FusedIterator}; +use core::mem::{replace, swap}; +use core::ops::{Add, Index, IndexMut, RangeBounds}; +use alloc::{vec::Vec, vec}; +use alloc::borrow::ToOwned; +use alloc::string::String; +use alloc::format; use sized_chunks::InlineArray; @@ -361,7 +365,7 @@ impl Vector { (left.is_empty() && right.is_empty()) || PoolRef::ptr_eq(left, right) } - if std::ptr::eq(self, other) { + if core::ptr::eq(self, other) { return true; } @@ -1182,7 +1186,7 @@ impl Vector { middle_level: tree.middle_level, outer_f: PoolRef::new(&pool.value_pool, of2), inner_f: replace_pool_def(&pool.value_pool, &mut tree.inner_f), - middle: std::mem::take(&mut tree.middle), + middle: core::mem::take(&mut tree.middle), inner_b: replace_pool_def(&pool.value_pool, &mut tree.inner_b), outer_b: replace_pool_def(&pool.value_pool, &mut tree.outer_b), }; @@ -1203,7 +1207,7 @@ impl Vector { middle_level: tree.middle_level, outer_f: PoolRef::new(&pool.value_pool, if2), inner_f: PoolRef::>::default(&pool.value_pool), - middle: std::mem::take(&mut tree.middle), + middle: core::mem::take(&mut tree.middle), inner_b: replace_pool_def(&pool.value_pool, &mut tree.inner_b), outer_b: replace_pool_def(&pool.value_pool, &mut tree.outer_b), }; @@ -1737,7 +1741,7 @@ impl PartialEq for Vector { (left.is_empty() && right.is_empty()) || PoolRef::ptr_eq(left, right) } - if std::ptr::eq(self, other) { + if core::ptr::eq(self, other) { return true; } @@ -2508,13 +2512,13 @@ mod test { #[test] fn issue_131() { - let smol = std::iter::repeat(42).take(64).collect::>(); + let smol = core::iter::repeat(42).take(64).collect::>(); let mut smol2 = smol.clone(); assert!(smol.ptr_eq(&smol2)); smol2.set(63, 420); assert!(!smol.ptr_eq(&smol2)); - let huge = std::iter::repeat(42).take(65).collect::>(); + let huge = core::iter::repeat(42).take(65).collect::>(); let mut huge2 = huge.clone(); assert!(huge.ptr_eq(&huge2)); huge2.set(63, 420); @@ -2524,7 +2528,7 @@ mod test { #[test] fn ptr_eq() { for len in 32..256 { - let input = std::iter::repeat(42).take(len).collect::>(); + let input = core::iter::repeat(42).take(len).collect::>(); let mut inp2 = input.clone(); assert!(input.ptr_eq(&inp2)); inp2.set(len - 1, 98);