1pub mod prelude {
2 pub use super::borrow::ToOwned;
6 pub use super::boxed::Box;
7 pub use super::cell::RefCell;
8 pub use super::clone::Clone;
9 pub use super::cmp::{Eq, Ord, PartialEq, PartialOrd};
10 pub use super::convert::{AsMut, AsRef, From, Into};
11 pub use super::default::Default;
12 pub use super::iter::{DoubleEndedIterator, ExactSizeIterator, Extend, IntoIterator, Iterator};
13 pub use super::marker::{Copy, Send, Sized, Sync, Unpin};
14 pub use super::mem::drop;
15 pub use super::ops::{Drop, Fn, FnMut, FnOnce};
16 pub use super::option::Option::{self, None, Some};
17 pub use super::result::Result::{self, Err, Ok};
18 pub use super::string::{String, ToString};
19 pub use super::vec::Vec;
20
21 pub use super::convert::{TryFrom, TryInto};
23 pub use super::iter::FromIterator;
24
25 pub use super::borrow;
27 pub use super::borrow::Cow;
28 pub use super::cell::*;
29 pub use super::collections::*;
30 pub use super::fmt;
31 pub use super::fmt::{Debug, Display};
32 pub use super::format;
33 pub use super::marker::PhantomData;
34 pub use super::mem;
35 pub use super::rc::Rc;
36 pub use super::str::FromStr;
37 pub use super::sync::Arc;
38 pub use super::vec;
39}
40
41#[cfg(feature = "alloc")]
42extern crate alloc;
43#[cfg(feature = "alloc")]
44pub use alloc::borrow;
45#[cfg(feature = "alloc")]
46pub use alloc::boxed;
47#[cfg(feature = "alloc")]
48pub use alloc::fmt;
49#[cfg(feature = "alloc")]
50pub use alloc::format;
51#[cfg(feature = "alloc")]
52pub use alloc::rc;
53#[cfg(feature = "alloc")]
54pub use alloc::str;
55#[cfg(feature = "alloc")]
56pub use alloc::string;
57#[cfg(feature = "alloc")]
58pub use alloc::sync;
59#[cfg(feature = "alloc")]
60pub use alloc::vec;
61#[cfg(feature = "alloc")]
62pub use core::cell;
63#[cfg(feature = "alloc")]
64pub use core::clone;
65#[cfg(feature = "alloc")]
66pub use core::cmp;
67#[cfg(feature = "alloc")]
68pub use core::convert;
69#[cfg(feature = "alloc")]
70pub use core::default;
71#[cfg(feature = "alloc")]
72pub use core::hash;
73#[cfg(feature = "alloc")]
74pub use core::iter;
75#[cfg(feature = "alloc")]
76pub use core::marker;
77#[cfg(feature = "alloc")]
78pub use core::mem;
79#[cfg(feature = "alloc")]
80pub use core::num;
81#[cfg(feature = "alloc")]
82pub use core::ops;
83#[cfg(feature = "alloc")]
84pub use core::option;
85#[cfg(feature = "alloc")]
86pub use core::ptr;
87#[cfg(feature = "alloc")]
88pub use core::result;
89#[cfg(feature = "alloc")]
90pub use core::slice;
91
92#[cfg(not(feature = "alloc"))]
93pub use core::hash;
94#[cfg(not(feature = "alloc"))]
95pub use std::alloc;
96#[cfg(not(feature = "alloc"))]
97pub use std::borrow;
98#[cfg(not(feature = "alloc"))]
99pub use std::boxed;
100#[cfg(not(feature = "alloc"))]
101pub use std::cell;
102#[cfg(not(feature = "alloc"))]
103pub use std::clone;
104#[cfg(not(feature = "alloc"))]
105pub use std::cmp;
106#[cfg(not(feature = "alloc"))]
107pub use std::convert;
108#[cfg(not(feature = "alloc"))]
109pub use std::default;
110#[cfg(not(feature = "alloc"))]
111pub use std::fmt;
112#[cfg(not(feature = "alloc"))]
113pub use std::format;
114#[cfg(not(feature = "alloc"))]
115pub use std::iter;
116#[cfg(not(feature = "alloc"))]
117pub use std::marker;
118#[cfg(not(feature = "alloc"))]
119pub use std::mem;
120#[cfg(not(feature = "alloc"))]
121pub use std::num;
122#[cfg(not(feature = "alloc"))]
123pub use std::ops;
124#[cfg(not(feature = "alloc"))]
125pub use std::option;
126#[cfg(not(feature = "alloc"))]
127pub use std::ptr;
128#[cfg(not(feature = "alloc"))]
129pub use std::rc;
130#[cfg(not(feature = "alloc"))]
131pub use std::result;
132#[cfg(not(feature = "alloc"))]
133pub use std::slice;
134#[cfg(not(feature = "alloc"))]
135pub use std::str;
136#[cfg(not(feature = "alloc"))]
137pub use std::string;
138#[cfg(not(feature = "alloc"))]
139pub use std::sync;
140#[cfg(not(feature = "alloc"))]
141pub use std::vec;
142
143pub mod collections {
145 #[cfg(feature = "alloc")]
146 extern crate alloc;
147
148 #[cfg(feature = "alloc")]
149 pub use alloc::collections::LinkedList;
150 #[cfg(not(feature = "alloc"))]
151 pub use std::collections::LinkedList;
152
153 #[cfg(feature = "alloc")]
154 pub use alloc::collections::VecDeque;
155 #[cfg(not(feature = "alloc"))]
156 pub use std::collections::VecDeque;
157
158 pub mod btree_map {
159 #[cfg(feature = "alloc")]
160 extern crate alloc;
161 #[cfg(feature = "alloc")]
162 pub use alloc::collections::btree_map::*;
163 #[cfg(not(feature = "alloc"))]
164 pub use std::collections::btree_map::*;
165
166 #[cfg(feature = "alloc")]
167 pub use alloc::collections::BTreeMap;
168 #[cfg(not(feature = "alloc"))]
169 pub use std::collections::BTreeMap;
170
171 #[macro_export]
172 macro_rules! btreemap {
173 ( ) => ({
174 $crate::rust::collections::btree_map::BTreeMap::new()
175 });
176 ( $($key:expr => $value:expr),* ) => ({
177 let mut temp = $crate::rust::collections::btree_map::BTreeMap::new();
178 $(
179 temp.insert($key, $value);
180 )*
181 temp
182 });
183 ( $($key:expr => $value:expr,)* ) => (
184 $crate::rust::collections::btree_map::btreemap!{$($key => $value),*}
185 );
186 }
187
188 pub use btreemap;
189 }
190
191 pub mod btree_set {
192 #[cfg(feature = "alloc")]
193 extern crate alloc;
194 #[cfg(feature = "alloc")]
195 pub use alloc::collections::btree_set::*;
196 #[cfg(not(feature = "alloc"))]
197 pub use std::collections::btree_set::*;
198
199 #[cfg(feature = "alloc")]
200 pub use alloc::collections::BTreeSet;
201 #[cfg(not(feature = "alloc"))]
202 pub use std::collections::BTreeSet;
203
204 #[macro_export]
205 macro_rules! btreeset {
206 ( ) => ({
207 $crate::rust::collections::btree_set::BTreeSet::new()
208 });
209 ( $($value:expr),* ) => ({
210 let mut temp = $crate::rust::collections::btree_set::BTreeSet::new();
211 $(
212 temp.insert($value);
213 )*
214 temp
215 });
216 ( $($value:expr,)* ) => (
217 $crate::rust::collections::btree_set::btreeset!{$($value),*}
218 );
219 }
220
221 pub use btreeset;
222 }
223
224 #[cfg(feature = "fuzzing")]
227 pub mod stub_hasher {
228 use core::hash::{BuildHasher, Hasher};
229
230 #[derive(Debug, Clone, PartialEq, Eq)]
231 pub struct StubHasher {
232 seed: u64,
233 }
234
235 impl Hasher for StubHasher {
236 fn write(&mut self, _bytes: &[u8]) {}
237
238 fn finish(&self) -> u64 {
239 self.seed
240 }
241 }
242
243 impl BuildHasher for StubHasher {
244 type Hasher = StubHasher;
245
246 fn build_hasher(&self) -> Self::Hasher {
247 StubHasher { seed: self.seed }
248 }
249 }
250
251 impl StubHasher {
252 fn new() -> Self {
253 StubHasher { seed: 0 }
254 }
255 }
256
257 impl Default for StubHasher {
258 fn default() -> Self {
259 StubHasher::new()
260 }
261 }
262 }
263
264 pub mod hash_map {
265 #[cfg(feature = "fuzzing")]
266 pub type DefaultHashBuilder = crate::rust::collections::stub_hasher::StubHasher;
267 #[cfg(all(not(feature = "fuzzing"), feature = "alloc"))]
268 pub type DefaultHashBuilder = hashbrown::hash_map::DefaultHashBuilder;
269 #[cfg(all(not(feature = "fuzzing"), not(feature = "alloc")))]
270 pub type DefaultHashBuilder = std::collections::hash_map::RandomState;
271
272 #[cfg(feature = "alloc")]
273 pub use hashbrown::hash_map::*;
274 #[cfg(not(feature = "alloc"))]
275 pub use std::collections::hash_map::*;
276
277 #[cfg(feature = "alloc")]
278 pub use hashbrown::HashMap as ext_HashMap;
279 #[cfg(not(feature = "alloc"))]
280 pub use std::collections::HashMap as ext_HashMap;
281
282 pub type HashMap<K, V, S = DefaultHashBuilder> = ext_HashMap<K, V, S>;
283
284 pub fn new<K, V>() -> HashMap<K, V> {
286 HashMap::with_capacity_and_hasher(0, DefaultHashBuilder::default())
287 }
288
289 pub fn with_capacity<K, V>(n: usize) -> HashMap<K, V> {
291 HashMap::with_capacity_and_hasher(n, DefaultHashBuilder::default())
292 }
293
294 #[macro_export]
295 macro_rules! hashmap {
296 ( ) => ({
297 $crate::rust::collections::hash_map::HashMap::default()
298 });
299 ( $($key:expr => $value:expr),* ) => ({
300 const CAP: usize = <[()]>::len(&[$({ stringify!($key); }),*]);
303 let mut temp = $crate::rust::collections::hash_map::HashMap::with_capacity(CAP);
304 $(
305 temp.insert($key, $value);
306 )*
307 temp
308 });
309 ( $($key:expr => $value:expr,)* ) => (
310 $crate::rust::collections::hash_map::hashmap!{$($key => $value),*}
311 );
312 }
313
314 pub use hashmap;
315 }
316
317 pub mod hash_set {
318 #[cfg(feature = "fuzzing")]
319 pub type DefaultHashBuilder = crate::rust::collections::stub_hasher::StubHasher;
320 #[cfg(all(not(feature = "fuzzing"), feature = "alloc"))]
321 pub type DefaultHashBuilder = hashbrown::hash_map::DefaultHashBuilder;
322 #[cfg(all(not(feature = "fuzzing"), not(feature = "alloc")))]
323 pub type DefaultHashBuilder = std::collections::hash_map::RandomState;
324
325 #[cfg(feature = "alloc")]
326 pub use hashbrown::hash_set::*;
327 #[cfg(not(feature = "alloc"))]
328 pub use std::collections::hash_set::*;
329
330 #[cfg(feature = "alloc")]
331 pub use hashbrown::HashSet as ext_HashSet;
332 #[cfg(not(feature = "alloc"))]
333 pub use std::collections::HashSet as ext_HashSet;
334
335 pub type HashSet<K> = ext_HashSet<K, DefaultHashBuilder>;
336
337 pub fn new<K>() -> HashSet<K> {
339 HashSet::with_capacity_and_hasher(0, DefaultHashBuilder::default())
340 }
341
342 pub fn with_capacity<K>(n: usize) -> HashSet<K> {
344 HashSet::with_capacity_and_hasher(n, DefaultHashBuilder::default())
345 }
346
347 #[macro_export]
348 macro_rules! hashset {
349 ( ) => ({
350 $crate::rust::collections::hash_set::HashSet::new()
351 });
352 ( $($key:expr),* ) => ({
353 const CAP: usize = <[()]>::len(&[$({ stringify!($key); }),*]);
356 let mut temp = $crate::rust::collections::hash_set::HashSet::with_capacity(CAP);
357 $(
358 temp.insert($key);
359 )*
360 temp
361 });
362 ( $($key:expr,)* ) => (
363 $crate::rust::collections::hash_set::hashset!{$($key),*}
364 );
365 }
366
367 pub use hashset;
368 }
369
370 pub mod index_map {
393 #[cfg(feature = "fuzzing")]
394 pub type DefaultHashBuilder = crate::rust::collections::stub_hasher::StubHasher;
395 #[cfg(all(not(feature = "fuzzing"), feature = "alloc"))]
396 pub type DefaultHashBuilder = hashbrown::hash_map::DefaultHashBuilder;
397 #[cfg(all(not(feature = "fuzzing"), not(feature = "alloc")))]
398 pub type DefaultHashBuilder = std::collections::hash_map::RandomState;
399
400 pub type IndexMap<K, V, S = DefaultHashBuilder> = indexmap::IndexMap<K, V, S>;
403
404 pub fn new<K, V>() -> IndexMap<K, V> {
407 IndexMap::with_capacity_and_hasher(0, DefaultHashBuilder::default())
408 }
409
410 pub fn with_capacity<K, V>(n: usize) -> IndexMap<K, V> {
413 IndexMap::with_capacity_and_hasher(n, DefaultHashBuilder::default())
414 }
415
416 #[macro_export]
417 macro_rules! indexmap {
418 ( ) => ({
419 $crate::rust::collections::index_map_new()
420 });
421 ($($key:expr => $value:expr,)+) => ( $crate::rust::collections::index_map::indexmap!{$($key => $value),*} );
422 ($($key:expr => $value:expr),*) => ({
423 const CAP: usize = <[()]>::len(&[$({ stringify!($key); }),*]);
426 let mut temp = $crate::rust::collections::index_map::with_capacity(CAP);
427 $(
428 temp.insert($key, $value);
429 )*
430 temp
431 });
432 }
433
434 pub use indexmap;
435 }
436
437 pub mod index_set {
455 #[cfg(feature = "fuzzing")]
456 pub type DefaultHashBuilder = crate::rust::collections::stub_hasher::StubHasher;
457 #[cfg(all(not(feature = "fuzzing"), feature = "alloc"))]
458 pub type DefaultHashBuilder = hashbrown::hash_map::DefaultHashBuilder;
459 #[cfg(all(not(feature = "fuzzing"), not(feature = "alloc")))]
460 pub type DefaultHashBuilder = std::collections::hash_map::RandomState;
461
462 pub type IndexSet<K, S = DefaultHashBuilder> = indexmap::IndexSet<K, S>;
465
466 pub fn new<K>() -> IndexSet<K, DefaultHashBuilder> {
469 IndexSet::with_hasher(DefaultHashBuilder::default())
470 }
471
472 pub fn with_capacity<K>(n: usize) -> IndexSet<K, DefaultHashBuilder> {
475 IndexSet::with_capacity_and_hasher(n, DefaultHashBuilder::default())
476 }
477
478 #[macro_export]
479 macro_rules! indexset {
480 () => ({
481 $crate::rust::collections::index_set_new()
482 });
483 ($($key:expr),+$(,)?) => ({
484 const CAP: usize = <[()]>::len(&[$({ stringify!($key); }),*]);
487 let mut temp = $crate::rust::collections::index_set::with_capacity(CAP);
488 $(
489 temp.insert($key);
490 )*
491 temp
492 });
493 }
494
495 pub use indexset;
496 }
497
498 pub mod non_iter_map {
499
500 #[cfg(feature = "alloc")]
501 use hashbrown::HashMap;
502 #[cfg(not(feature = "alloc"))]
503 use std::collections::HashMap;
504
505 #[cfg(feature = "alloc")]
506 use core::hash::Hash;
507 #[cfg(not(feature = "alloc"))]
508 use core::hash::Hash;
509
510 #[cfg(feature = "alloc")]
511 use core::borrow::Borrow;
512 #[cfg(not(feature = "alloc"))]
513 use std::borrow::Borrow;
514
515 #[cfg(feature = "fuzzing")]
516 pub type DefaultHashBuilder = crate::rust::collections::stub_hasher::StubHasher;
517 #[cfg(all(not(feature = "fuzzing"), feature = "alloc"))]
518 pub type DefaultHashBuilder = hashbrown::hash_map::DefaultHashBuilder;
519 #[cfg(all(not(feature = "fuzzing"), not(feature = "alloc")))]
520 pub type DefaultHashBuilder = std::collections::hash_map::RandomState;
521
522 #[derive(Debug, Clone, PartialEq, Eq)]
526 pub struct NonIterMap<K: Eq + Hash, V, S: core::hash::BuildHasher = DefaultHashBuilder>(
527 HashMap<K, V, S>,
528 );
529
530 #[cfg(feature = "alloc")]
531 pub type Entry<'a, K, V> = hashbrown::hash_map::Entry<'a, K, V, DefaultHashBuilder>;
532 #[cfg(not(feature = "alloc"))]
533 pub type Entry<'a, K, V> = std::collections::hash_map::Entry<'a, K, V>;
534
535 impl<K: Hash + Eq, V> NonIterMap<K, V> {
536 pub fn new() -> Self {
538 Self(HashMap::with_hasher(DefaultHashBuilder::default()))
539 }
540
541 pub fn entry(&mut self, key: K) -> Entry<K, V> {
543 self.0.entry(key)
544 }
545
546 pub fn insert(&mut self, key: K, value: V) -> Option<V> {
551 self.0.insert(key, value)
552 }
553
554 pub fn get<Q: ?Sized>(&self, key: &Q) -> Option<&V>
556 where
557 Q: Hash + Eq,
558 K: Borrow<Q>,
559 {
560 self.0.get(key)
561 }
562
563 pub fn get_mut<Q: ?Sized>(&mut self, key: &Q) -> Option<&mut V>
565 where
566 Q: Hash + Eq,
567 K: Borrow<Q>,
568 {
569 self.0.get_mut(key)
570 }
571
572 pub fn contains_key<Q: ?Sized>(&self, key: &Q) -> bool
574 where
575 Q: Hash + Eq,
576 K: Borrow<Q>,
577 {
578 self.0.contains_key(key)
579 }
580
581 pub fn remove<Q: ?Sized>(&mut self, key: &Q) -> Option<V>
584 where
585 Q: Hash + Eq,
586 K: Borrow<Q>,
587 {
588 self.0.remove(key)
589 }
590
591 pub fn clear(&mut self) {
593 self.0.clear();
594 }
595
596 pub fn len(&self) -> usize {
598 self.0.len()
599 }
600
601 pub fn is_empty(&self) -> bool {
603 self.0.is_empty()
604 }
605 }
606
607 impl<K: Hash + Eq, V> Default for NonIterMap<K, V> {
608 fn default() -> Self {
609 Self::new()
610 }
611 }
612
613 impl<K: Hash + Eq, V> FromIterator<(K, V)> for NonIterMap<K, V> {
614 fn from_iter<T: IntoIterator<Item = (K, V)>>(iter: T) -> Self {
615 Self(HashMap::from_iter(iter))
616 }
617 }
618 }
619
620 pub use btree_map::btreemap;
621 pub use btree_map::BTreeMap;
622 pub use btree_set::btreeset;
623 pub use btree_set::BTreeSet;
624 pub use hash_map::hashmap;
625 pub use hash_map::HashMap;
626 pub use hash_map::{new as hash_map_new, with_capacity as hash_map_with_capacity};
627 pub use hash_set::hashset;
628 pub use hash_set::HashSet;
629 pub use hash_set::{new as hash_set_new, with_capacity as hash_set_with_capacity};
630 pub use index_map::indexmap;
631 pub use index_map::IndexMap;
632 pub use index_map::{new as index_map_new, with_capacity as index_map_with_capacity};
633 pub use index_set::indexset;
634 pub use index_set::IndexSet;
635 pub use index_set::{new as index_set_new, with_capacity as index_set_with_capacity};
636 pub use non_iter_map::NonIterMap;
637}