1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#[cfg(feature = "alloc")]
use std::boxed::Box;
mod array;
#[cfg(any(doc, feature = "alloc"))]
mod heap;
mod slice;
mod uninit;
mod zero_sized;
mod capacity;
#[cfg(any(doc, feature = "alloc"))]
pub use heap::Heap;
pub use slice::UninitSlice;
pub use uninit::UninitBuffer;
pub use zero_sized::ZeroSized;
pub unsafe trait StorageInit<T>: Storage<T> {}
pub unsafe trait Storage<T> {
#[doc(hidden)]
const CONST_CAPACITY: Option<usize> = None;
const IS_ALIGNED: bool;
fn capacity(&self) -> usize;
fn as_ptr(&self) -> *const T;
fn as_mut_ptr(&mut self) -> *mut T;
fn reserve(&mut self, new_capacity: usize);
fn try_reserve(&mut self, new_capacity: usize) -> bool;
}
pub unsafe trait StorageWithCapacity<T>: Storage<T> + Default {
fn with_capacity(capacity: usize) -> Self;
#[doc(hidden)]
#[inline(always)]
#[allow(non_snake_case)]
fn __with_capacity__const_capacity_checked(capacity: usize, _old_capacity: Option<usize>) -> Self {
Self::with_capacity(capacity)
}
}
unsafe impl<T, S: ?Sized + StorageInit<T>> StorageInit<T> for &mut S {}
unsafe impl<T, S: ?Sized + Storage<T>> Storage<T> for &mut S {
#[doc(hidden)]
const CONST_CAPACITY: Option<usize> = S::CONST_CAPACITY;
const IS_ALIGNED: bool = S::IS_ALIGNED;
#[inline]
fn capacity(&self) -> usize { S::capacity(self) }
#[inline]
fn as_ptr(&self) -> *const T { S::as_ptr(self) }
#[inline]
fn as_mut_ptr(&mut self) -> *mut T { S::as_mut_ptr(self) }
#[inline]
fn reserve(&mut self, new_capacity: usize) { S::reserve(self, new_capacity) }
#[inline]
fn try_reserve(&mut self, new_capacity: usize) -> bool { S::try_reserve(self, new_capacity) }
}
#[cfg(any(doc, feature = "alloc"))]
unsafe impl<T, S: ?Sized + StorageInit<T>> StorageInit<T> for Box<S> {}
#[cfg(any(doc, feature = "alloc"))]
unsafe impl<T, S: ?Sized + Storage<T>> Storage<T> for Box<S> {
#[doc(hidden)]
const CONST_CAPACITY: Option<usize> = S::CONST_CAPACITY;
const IS_ALIGNED: bool = S::IS_ALIGNED;
#[inline]
fn capacity(&self) -> usize { S::capacity(self) }
#[inline]
fn as_ptr(&self) -> *const T { S::as_ptr(self) }
#[inline]
fn as_mut_ptr(&mut self) -> *mut T { S::as_mut_ptr(self) }
#[inline]
fn reserve(&mut self, new_capacity: usize) { S::reserve(self, new_capacity) }
#[inline]
fn try_reserve(&mut self, new_capacity: usize) -> bool { S::try_reserve(self, new_capacity) }
}
#[cfg(any(doc, feature = "alloc"))]
unsafe impl<T, S: ?Sized + StorageWithCapacity<T>> StorageWithCapacity<T> for Box<S> {
#[inline(always)]
fn with_capacity(capacity: usize) -> Self { Box::new(S::with_capacity(capacity)) }
#[doc(hidden)]
#[inline(always)]
#[allow(non_snake_case)]
fn __with_capacity__const_capacity_checked(capacity: usize, _old_capacity: Option<usize>) -> Self {
Box::new(S::__with_capacity__const_capacity_checked(capacity, _old_capacity))
}
}