mirror of
https://github.com/openharmony/third_party_rust_indexmap.git
synced 2026-07-19 16:43:59 -04:00
Always use #![nostd] and make std:: explicit
The fake `std` module we had in our root will make things difficult when we switch to 2018, where there's a path difference between `std::` for the crate and `crate::std::` for our module.
This commit is contained in:
+1
-1
@@ -1,4 +1,4 @@
|
||||
use std::borrow::Borrow;
|
||||
use core::borrow::Borrow;
|
||||
|
||||
/// Key equivalence trait.
|
||||
///
|
||||
|
||||
+8
-13
@@ -1,7 +1,7 @@
|
||||
// We *mostly* avoid unsafe code, but `map::core::raw` allows it to use `RawTable` buckets.
|
||||
#![deny(unsafe_code)]
|
||||
#![doc(html_root_url = "https://docs.rs/indexmap/1/")]
|
||||
#![cfg_attr(not(has_std), no_std)]
|
||||
#![no_std]
|
||||
|
||||
//! [`IndexMap`] is a hash table where the iteration order of the key-value
|
||||
//! pairs is independent of the hash values of the keys.
|
||||
@@ -82,22 +82,17 @@
|
||||
#[cfg(not(has_std))]
|
||||
extern crate alloc;
|
||||
|
||||
#[cfg(has_std)]
|
||||
#[macro_use]
|
||||
extern crate std;
|
||||
|
||||
extern crate hashbrown;
|
||||
|
||||
#[cfg(not(has_std))]
|
||||
pub(crate) mod std {
|
||||
pub use core::*;
|
||||
pub mod alloc {
|
||||
pub use alloc::*;
|
||||
}
|
||||
pub mod collections {
|
||||
pub use alloc::collections::*;
|
||||
}
|
||||
pub use alloc::vec;
|
||||
}
|
||||
use alloc::vec::{self, Vec};
|
||||
|
||||
#[cfg(not(has_std))]
|
||||
use std::vec::Vec;
|
||||
#[cfg(has_std)]
|
||||
use std::vec::{self, Vec};
|
||||
|
||||
#[macro_use]
|
||||
mod macros;
|
||||
|
||||
+11
-21
@@ -3,26 +3,22 @@
|
||||
|
||||
mod core;
|
||||
|
||||
#[cfg(not(has_std))]
|
||||
use std::vec::Vec;
|
||||
|
||||
pub use mutable_keys::MutableKeys;
|
||||
|
||||
#[cfg(feature = "rayon")]
|
||||
pub use rayon::map as rayon;
|
||||
|
||||
use std::hash::BuildHasher;
|
||||
use std::hash::Hash;
|
||||
use std::hash::Hasher;
|
||||
use std::iter::FromIterator;
|
||||
use std::ops::RangeFull;
|
||||
use core::cmp::Ordering;
|
||||
use core::fmt;
|
||||
use core::hash::{BuildHasher, Hash, Hasher};
|
||||
use core::iter::FromIterator;
|
||||
use core::ops::{Index, IndexMut, RangeFull};
|
||||
use core::slice::{Iter as SliceIter, IterMut as SliceIterMut};
|
||||
use vec::{self, Vec};
|
||||
|
||||
#[cfg(has_std)]
|
||||
use std::collections::hash_map::RandomState;
|
||||
|
||||
use std::cmp::Ordering;
|
||||
use std::fmt;
|
||||
|
||||
use self::core::IndexMapCore;
|
||||
use equivalent::Equivalent;
|
||||
use util::third;
|
||||
@@ -720,10 +716,6 @@ impl<K, V, S> IndexMap<K, V, S> {
|
||||
}
|
||||
}
|
||||
|
||||
use std::slice::Iter as SliceIter;
|
||||
use std::slice::IterMut as SliceIterMut;
|
||||
use std::vec::IntoIter as VecIntoIter;
|
||||
|
||||
/// An iterator over the keys of a `IndexMap`.
|
||||
///
|
||||
/// This `struct` is created by the [`keys`] method on [`IndexMap`]. See its
|
||||
@@ -922,7 +914,7 @@ impl<'a, K, V> ExactSizeIterator for IterMut<'a, K, V> {
|
||||
/// [`into_iter`]: struct.IndexMap.html#method.into_iter
|
||||
/// [`IndexMap`]: struct.IndexMap.html
|
||||
pub struct IntoIter<K, V> {
|
||||
pub(crate) iter: VecIntoIter<Bucket<K, V>>,
|
||||
pub(crate) iter: vec::IntoIter<Bucket<K, V>>,
|
||||
}
|
||||
|
||||
impl<K, V> Iterator for IntoIter<K, V> {
|
||||
@@ -962,7 +954,7 @@ where
|
||||
K: 'a,
|
||||
V: 'a,
|
||||
{
|
||||
pub(crate) iter: ::std::vec::Drain<'a, Bucket<K, V>>,
|
||||
pub(crate) iter: vec::Drain<'a, Bucket<K, V>>,
|
||||
}
|
||||
|
||||
impl<'a, K, V> Iterator for Drain<'a, K, V> {
|
||||
@@ -1013,8 +1005,6 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
use std::ops::{Index, IndexMut};
|
||||
|
||||
impl<'a, K, V, Q: ?Sized, S> Index<&'a Q> for IndexMap<K, V, S>
|
||||
where
|
||||
Q: Hash + Equivalent<K>,
|
||||
@@ -1149,6 +1139,7 @@ where
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use std::string::String;
|
||||
use util::enumerate;
|
||||
|
||||
#[test]
|
||||
@@ -1405,8 +1396,7 @@ mod tests {
|
||||
map_b.swap_remove(&1);
|
||||
assert_ne!(map_a, map_b);
|
||||
|
||||
let map_c: IndexMap<_, String> =
|
||||
map_b.into_iter().map(|(k, v)| (k, v.to_owned())).collect();
|
||||
let map_c: IndexMap<_, String> = map_b.into_iter().map(|(k, v)| (k, v.into())).collect();
|
||||
assert_ne!(map_a, map_c);
|
||||
assert_ne!(map_c, map_a);
|
||||
}
|
||||
|
||||
+5
-8
@@ -9,16 +9,13 @@
|
||||
|
||||
mod raw;
|
||||
|
||||
#[cfg(not(has_std))]
|
||||
use std::vec::Vec;
|
||||
|
||||
use hashbrown::raw::RawTable;
|
||||
|
||||
use std::cmp;
|
||||
use std::fmt;
|
||||
use std::mem::replace;
|
||||
use std::ops::RangeFull;
|
||||
use std::vec::Drain;
|
||||
use core::cmp;
|
||||
use core::fmt;
|
||||
use core::mem::replace;
|
||||
use core::ops::RangeFull;
|
||||
use vec::{Drain, Vec};
|
||||
|
||||
use equivalent::Equivalent;
|
||||
use util::enumerate;
|
||||
|
||||
+2
-2
@@ -3,9 +3,9 @@
|
||||
//! mostly in dealing with its bucket "pointers".
|
||||
|
||||
use super::{Entry, Equivalent, HashValue, IndexMapCore, VacantEntry};
|
||||
use core::fmt;
|
||||
use core::mem::replace;
|
||||
use hashbrown::raw::RawTable;
|
||||
use std::fmt;
|
||||
use std::mem::replace;
|
||||
|
||||
type RawBucket = hashbrown::raw::Bucket<usize>;
|
||||
|
||||
|
||||
+1
-2
@@ -1,5 +1,4 @@
|
||||
use std::hash::BuildHasher;
|
||||
use std::hash::Hash;
|
||||
use core::hash::{BuildHasher, Hash};
|
||||
|
||||
use super::{Equivalent, IndexMap};
|
||||
|
||||
|
||||
+7
-8
@@ -9,10 +9,10 @@ use super::collect;
|
||||
use super::rayon::iter::plumbing::{Consumer, ProducerCallback, UnindexedConsumer};
|
||||
use super::rayon::prelude::*;
|
||||
|
||||
use std::cmp::Ordering;
|
||||
use std::fmt;
|
||||
use std::hash::BuildHasher;
|
||||
use std::hash::Hash;
|
||||
use core::cmp::Ordering;
|
||||
use core::fmt;
|
||||
use core::hash::{BuildHasher, Hash};
|
||||
use vec::Vec;
|
||||
|
||||
use Bucket;
|
||||
use Entries;
|
||||
@@ -398,6 +398,7 @@ where
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use std::string::String;
|
||||
|
||||
#[test]
|
||||
fn insert_order() {
|
||||
@@ -433,10 +434,8 @@ mod tests {
|
||||
map_b.insert(3, "3");
|
||||
assert!(!map_a.par_eq(&map_b));
|
||||
|
||||
let map_c: IndexMap<_, String> = map_b
|
||||
.into_par_iter()
|
||||
.map(|(k, v)| (k, v.to_owned()))
|
||||
.collect();
|
||||
let map_c: IndexMap<_, String> =
|
||||
map_b.into_par_iter().map(|(k, v)| (k, v.into())).collect();
|
||||
assert!(!map_a.par_eq(&map_c));
|
||||
assert!(!map_c.par_eq(&map_a));
|
||||
}
|
||||
|
||||
@@ -2,8 +2,14 @@ extern crate rayon;
|
||||
|
||||
use self::rayon::prelude::*;
|
||||
|
||||
#[cfg(not(has_std))]
|
||||
use alloc::collections::LinkedList;
|
||||
|
||||
#[cfg(has_std)]
|
||||
use std::collections::LinkedList;
|
||||
|
||||
use vec::Vec;
|
||||
|
||||
// generate `ParallelIterator` methods by just forwarding to the underlying
|
||||
// self.entries and mapping its elements.
|
||||
macro_rules! parallel_iterator_methods {
|
||||
|
||||
+4
-4
@@ -9,10 +9,10 @@ use super::collect;
|
||||
use super::rayon::iter::plumbing::{Consumer, ProducerCallback, UnindexedConsumer};
|
||||
use super::rayon::prelude::*;
|
||||
|
||||
use std::cmp::Ordering;
|
||||
use std::fmt;
|
||||
use std::hash::BuildHasher;
|
||||
use std::hash::Hash;
|
||||
use core::cmp::Ordering;
|
||||
use core::fmt;
|
||||
use core::hash::{BuildHasher, Hash};
|
||||
use vec::Vec;
|
||||
|
||||
use Entries;
|
||||
use IndexSet;
|
||||
|
||||
+3
-3
@@ -6,9 +6,9 @@ use self::serde::de::{
|
||||
};
|
||||
use self::serde::ser::{Serialize, SerializeMap, SerializeSeq, Serializer};
|
||||
|
||||
use std::fmt::{self, Formatter};
|
||||
use std::hash::{BuildHasher, Hash};
|
||||
use std::marker::PhantomData;
|
||||
use core::fmt::{self, Formatter};
|
||||
use core::hash::{BuildHasher, Hash};
|
||||
use core::marker::PhantomData;
|
||||
|
||||
use IndexMap;
|
||||
|
||||
|
||||
+8
-11
@@ -3,20 +3,16 @@
|
||||
#[cfg(feature = "rayon")]
|
||||
pub use rayon::set as rayon;
|
||||
|
||||
#[cfg(not(has_std))]
|
||||
use std::vec::Vec;
|
||||
|
||||
#[cfg(has_std)]
|
||||
use std::collections::hash_map::RandomState;
|
||||
|
||||
use std::cmp::Ordering;
|
||||
use std::fmt;
|
||||
use std::hash::{BuildHasher, Hash};
|
||||
use std::iter::{Chain, FromIterator};
|
||||
use std::ops::RangeFull;
|
||||
use std::ops::{BitAnd, BitOr, BitXor, Sub};
|
||||
use std::slice;
|
||||
use std::vec;
|
||||
use core::cmp::Ordering;
|
||||
use core::fmt;
|
||||
use core::hash::{BuildHasher, Hash};
|
||||
use core::iter::{Chain, FromIterator};
|
||||
use core::ops::{BitAnd, BitOr, BitXor, RangeFull, Sub};
|
||||
use core::slice;
|
||||
use vec::{self, Vec};
|
||||
|
||||
use super::{Entries, Equivalent, IndexMap};
|
||||
|
||||
@@ -1163,6 +1159,7 @@ where
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use std::string::String;
|
||||
use util::enumerate;
|
||||
|
||||
#[test]
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
use std::iter::Enumerate;
|
||||
use core::iter::Enumerate;
|
||||
|
||||
pub(crate) fn third<A, B, C>(t: (A, B, C)) -> C {
|
||||
t.2
|
||||
|
||||
Reference in New Issue
Block a user