7
7
//! - Optional, enabled by default
8
8
//! - Use libstd; disable to use `no_std` instead.
9
9
//!
10
- //! - `use_union`
11
- //! - Optional
12
- //! - Requires Rust nightly channel
13
- //! - Experimental: This flag uses nightly so it *may break* unexpectedly
14
- //! at some point; since it doesn't change API this flag may also change
15
- //! to do nothing in the future.
16
- //! - Use the unstable feature untagged unions for the internal implementation,
17
- //! which may have reduced space overhead
18
10
//! - `serde-1`
19
11
//! - Optional
20
12
//! - Enable serialization for ArrayVec and ArrayString using serde 1.0
28
20
//!
29
21
#![ doc( html_root_url="https://docs.rs/arrayvec/0.4/" ) ]
30
22
#![ cfg_attr( not( feature="std" ) , no_std) ]
23
+
31
24
extern crate nodrop;
32
25
#[ cfg( feature="serde-1" ) ]
33
26
extern crate serde;
@@ -53,11 +46,16 @@ use std::fmt;
53
46
#[ cfg( feature="std" ) ]
54
47
use std:: io;
55
48
56
- #[ cfg( not( feature="use_union" ) ) ]
57
- use nodrop:: NoDrop ;
58
49
59
- #[ cfg( feature="use_union" ) ]
60
- use std:: mem:: ManuallyDrop as NoDrop ;
50
+ #[ cfg( has_manuallydrop) ]
51
+ mod maybe_uninit;
52
+ #[ cfg( has_manuallydrop) ]
53
+ use maybe_uninit:: MaybeUninit ;
54
+
55
+ #[ cfg( not( has_manuallydrop) ) ]
56
+ mod maybe_uninit_nodrop;
57
+ #[ cfg( not( has_manuallydrop) ) ]
58
+ use maybe_uninit_nodrop:: MaybeUninit ;
61
59
62
60
#[ cfg( feature="serde-1" ) ]
63
61
use serde:: { Serialize , Deserialize , Serializer , Deserializer } ;
@@ -96,7 +94,7 @@ unsafe fn new_array<A: Array>() -> A {
96
94
///
97
95
/// ArrayVec can be converted into a by value iterator.
98
96
pub struct ArrayVec < A : Array > {
99
- xs : NoDrop < A > ,
97
+ xs : MaybeUninit < A > ,
100
98
len : A :: Index ,
101
99
}
102
100
@@ -133,7 +131,7 @@ impl<A: Array> ArrayVec<A> {
133
131
/// ```
134
132
pub fn new ( ) -> ArrayVec < A > {
135
133
unsafe {
136
- ArrayVec { xs : NoDrop :: new ( new_array ( ) ) , len : Index :: from ( 0 ) }
134
+ ArrayVec { xs : MaybeUninit :: uninitialized ( ) , len : Index :: from ( 0 ) }
137
135
}
138
136
}
139
137
@@ -583,7 +581,7 @@ impl<A: Array> ArrayVec<A> {
583
581
Err ( self )
584
582
} else {
585
583
unsafe {
586
- let array = ptr:: read ( & * self . xs ) ;
584
+ let array = ptr:: read ( self . xs . ptr ( ) ) ;
587
585
mem:: forget ( self ) ;
588
586
Ok ( array)
589
587
}
@@ -612,7 +610,7 @@ impl<A: Array> Deref for ArrayVec<A> {
612
610
#[ inline]
613
611
fn deref ( & self ) -> & [ A :: Item ] {
614
612
unsafe {
615
- slice:: from_raw_parts ( self . xs . as_ptr ( ) , self . len ( ) )
613
+ slice:: from_raw_parts ( ( * self . xs . ptr ( ) ) . as_ptr ( ) , self . len ( ) )
616
614
}
617
615
}
618
616
}
@@ -622,7 +620,7 @@ impl<A: Array> DerefMut for ArrayVec<A> {
622
620
fn deref_mut ( & mut self ) -> & mut [ A :: Item ] {
623
621
let len = self . len ( ) ;
624
622
unsafe {
625
- slice:: from_raw_parts_mut ( self . xs . as_mut_ptr ( ) , len)
623
+ slice:: from_raw_parts_mut ( ( * self . xs . ptr_mut ( ) ) . as_mut_ptr ( ) , len)
626
624
}
627
625
}
628
626
}
@@ -638,7 +636,7 @@ impl<A: Array> DerefMut for ArrayVec<A> {
638
636
/// ```
639
637
impl < A : Array > From < A > for ArrayVec < A > {
640
638
fn from ( array : A ) -> Self {
641
- ArrayVec { xs : NoDrop :: new ( array) , len : Index :: from ( A :: capacity ( ) ) }
639
+ ArrayVec { xs : MaybeUninit :: from ( array) , len : Index :: from ( A :: capacity ( ) ) }
642
640
}
643
641
}
644
642
0 commit comments