28
28
//! To use this feature add `features = ["union"]` in the `smallvec` section of Cargo.toml.
29
29
//! Note that this feature requires a nightly compiler (for now).
30
30
31
- #![ cfg_attr( not( feature = "std" ) , no_std) ]
32
- #![ cfg_attr( not( feature = "std" ) , feature( alloc) ) ]
33
- #![ cfg_attr( feature = "union" , feature( untagged_unions) ) ]
34
- #![ cfg_attr( feature = "specialization" , feature( specialization) ) ]
35
31
#![ cfg_attr( feature = "may_dangle" , feature( dropck_eyepatch) ) ]
32
+ #![ cfg_attr( feature = "specialization" , feature( specialization) ) ]
33
+ #![ cfg_attr( feature = "union" , feature( untagged_unions) ) ]
34
+ #![ cfg_attr( not( feature = "alloc" ) , no_std) ]
36
35
#![ deny( missing_docs) ]
37
36
38
-
39
- #[ cfg( not( feature = "std" ) ) ]
40
- #[ macro_use]
37
+ #[ cfg( feature = "alloc" ) ]
41
38
extern crate alloc;
42
39
43
- #[ cfg( not( feature = "std" ) ) ]
44
- use alloc:: vec:: Vec ;
45
-
46
40
#[ cfg( feature = "serde" ) ]
47
41
extern crate serde;
48
42
49
- #[ cfg( not( feature = "std" ) ) ]
50
- mod std {
51
- pub use core:: * ;
52
- }
53
-
54
- use std:: borrow:: { Borrow , BorrowMut } ;
55
- use std:: cmp;
56
- use std:: fmt;
57
- use std:: hash:: { Hash , Hasher } ;
58
- use std:: iter:: { IntoIterator , FromIterator , repeat} ;
59
- use std:: mem;
60
- use std:: mem:: ManuallyDrop ;
61
- use std:: ops;
62
- use std:: ptr;
63
- use std:: slice;
43
+ use core:: {
44
+ borrow:: { Borrow , BorrowMut } ,
45
+ cmp,
46
+ fmt,
47
+ hash:: { Hash , Hasher } ,
48
+ iter:: { IntoIterator , FromIterator , repeat} ,
49
+ mem:: { ManuallyDrop , self } ,
50
+ ops,
51
+ ptr,
52
+ slice,
53
+ } ;
64
54
#[ cfg( feature = "std" ) ]
65
55
use std:: io;
66
56
#[ cfg( feature = "serde" ) ]
67
- use serde:: ser:: { Serialize , Serializer , SerializeSeq } ;
68
- #[ cfg( feature = "serde" ) ]
69
- use serde:: de:: { Deserialize , Deserializer , SeqAccess , Visitor } ;
70
- #[ cfg( feature = "serde" ) ]
71
- use std:: marker:: PhantomData ;
57
+ use {
58
+ serde:: {
59
+ ser:: { Serialize , Serializer , SerializeSeq } ,
60
+ de:: { Deserialize , Deserializer , SeqAccess , Visitor } ,
61
+ } ,
62
+ core:: marker:: PhantomData
63
+ } ;
72
64
73
65
/// Creates a [`SmallVec`] containing the arguments.
74
66
///
@@ -821,7 +813,7 @@ impl<A: Array> SmallVec<A> {
821
813
}
822
814
823
815
let ( lower_size_bound, _) = iter. size_hint ( ) ;
824
- assert ! ( lower_size_bound <= std :: isize :: MAX as usize ) ; // Ensure offset is indexable
816
+ assert ! ( lower_size_bound <= core :: isize :: MAX as usize ) ; // Ensure offset is indexable
825
817
assert ! ( index + lower_size_bound >= index) ; // Protect against overflow
826
818
self . reserve ( lower_size_bound) ;
827
819
@@ -1121,7 +1113,7 @@ impl<A: Array> SmallVec<A> where A::Item: Clone {
1121
1113
let mut local_len = SetLenOnDrop :: new ( len_ptr) ;
1122
1114
1123
1115
for i in 0 ..n as isize {
1124
- :: std :: ptr:: write ( ptr. offset ( i) , elem. clone ( ) ) ;
1116
+ core :: ptr:: write ( ptr. offset ( i) , elem. clone ( ) ) ;
1125
1117
local_len. increment_len ( 1 ) ;
1126
1118
}
1127
1119
}
@@ -1606,9 +1598,9 @@ impl_array!(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 20, 24, 32
1606
1598
1607
1599
#[ cfg( test) ]
1608
1600
mod tests {
1609
- use SmallVec ;
1601
+ use crate :: SmallVec ;
1610
1602
1611
- use std :: iter:: FromIterator ;
1603
+ use core :: iter:: FromIterator ;
1612
1604
1613
1605
#[ cfg( feature = "std" ) ]
1614
1606
use std:: borrow:: ToOwned ;
@@ -1766,7 +1758,7 @@ mod tests {
1766
1758
1767
1759
#[ test]
1768
1760
fn into_iter_drop ( ) {
1769
- use std :: cell:: Cell ;
1761
+ use core :: cell:: Cell ;
1770
1762
1771
1763
struct DropCounter < ' a > ( & ' a Cell < i32 > ) ;
1772
1764
@@ -2061,7 +2053,7 @@ mod tests {
2061
2053
2062
2054
#[ test]
2063
2055
fn test_borrow ( ) {
2064
- use std :: borrow:: Borrow ;
2056
+ use core :: borrow:: Borrow ;
2065
2057
2066
2058
let mut a: SmallVec < [ u32 ; 2 ] > = SmallVec :: new ( ) ;
2067
2059
a. push ( 1 ) ;
@@ -2074,7 +2066,7 @@ mod tests {
2074
2066
2075
2067
#[ test]
2076
2068
fn test_borrow_mut ( ) {
2077
- use std :: borrow:: BorrowMut ;
2069
+ use core :: borrow:: BorrowMut ;
2078
2070
2079
2071
let mut a: SmallVec < [ u32 ; 2 ] > = SmallVec :: new ( ) ;
2080
2072
a. push ( 1 ) ;
@@ -2279,7 +2271,7 @@ mod tests {
2279
2271
#[ cfg( feature = "std" ) ]
2280
2272
#[ test]
2281
2273
fn test_write ( ) {
2282
- use io:: Write ;
2274
+ use std :: io:: Write ;
2283
2275
2284
2276
let data = [ 1 , 2 , 3 , 4 , 5 ] ;
2285
2277
0 commit comments