Skip to content

Commit 37ccc54

Browse files
committed
Tweak methods
1 parent b50e3f7 commit 37ccc54

File tree

1 file changed

+27
-25
lines changed

1 file changed

+27
-25
lines changed

text/2978-stack_based_vec.md

+27-25
Original file line numberDiff line numberDiff line change
@@ -125,88 +125,90 @@ impl<T, const N: usize> ArrayVec<T, N> {
125125
// Constructors
126126

127127
#[inline]
128-
pub fn from_array(array: [T; N]) -> Self;
128+
pub const fn from_array(array: [T; N]) -> Self;
129129

130130
#[inline]
131-
pub fn from_array_and_len(array: [T; N], len: usize) -> Self;
131+
pub const fn from_array_and_len(array: [T; N], len: usize) -> Self;
132132

133133
#[inline]
134134
pub const fn new() -> Self;
135135

136136
// Methods
137137

138138
#[inline]
139-
pub fn as_mut_ptr(&mut self) -> *mut T;
139+
pub const fn as_mut_ptr(&mut self) -> *mut T;
140140

141141
#[inline]
142142
pub fn as_mut_slice(&mut self) -> &mut [T];
143143

144144
#[inline]
145-
pub fn as_ptr(&self) -> *const T;
145+
pub const fn as_ptr(&self) -> *const T;
146146

147147
#[inline]
148148
pub fn as_slice(&self) -> &[T];
149149

150150
#[inline]
151151
pub const fn capacity(&self) -> usize;
152152

153-
pub fn clear(&mut self);
153+
#[inline]
154+
pub const fn clear(&mut self);
154155

155-
pub fn dedup(&mut self);
156+
pub fn dedup(&mut self)
157+
where
158+
T: PartialEq;
156159

157160
pub fn dedup_by<F>(&mut self, same_bucket: F)
158161
where
159162
F: FnMut(&mut T, &mut T) -> bool;
160163

161-
pub fn dedup_by_key<F, K>(&mut self, key: F)
164+
pub fn dedup_by_key<F, K>(&mut self, mut key: F)
162165
where
163166
F: FnMut(&mut T) -> K,
164167
K: PartialEq<K>;
165168

166-
pub fn drain<R>(&mut self, range: R)
169+
pub fn drain<R>(&mut self, range: R) -> Option<Drain<'_, T, N>>
167170
where
168171
R: RangeBounds<usize>;
169172

170-
pub fn extend_from_cloneable_slice(&mut self, other: &[T]) -> Result<(), &[T]>
173+
pub fn extend_from_cloneable_slice<'a>(&mut self, other: &'a [T]) -> Result<(), &'a [T]>
171174
where
172175
T: Clone;
173176

174-
pub fn extend_from_copyable_slice(&mut self, other: &[T]) -> Result<(), &[T]>
177+
178+
pub fn extend_from_copyable_slice<'a>(&mut self, other: &'a [T]) -> Result<(), &'a [T]>
175179
where
176180
T: Copy;
177181

178-
pub fn insert(&mut self, _idx: usize, element: T) -> Result<(), T>;
182+
pub fn insert(&mut self, idx: usize, element: T) -> Result<(), T>;
179183

180184
#[inline]
181185
pub const fn is_empty(&self) -> bool;
182-
186+
183187
#[inline]
184188
pub const fn len(&self) -> usize;
185-
189+
190+
#[inline]
186191
pub fn pop(&mut self) -> Option<T>;
187192

188193
#[inline]
189194
pub fn push(&mut self, element: T) -> Result<(), T>;
190195

196+
#[inline]
191197
pub fn remove(&mut self, idx: usize) -> Option<T>;
192198

193-
pub fn retain<F>(&mut self, f: F)
199+
pub fn retain<F>(&mut self, mut f: F)
194200
where
195201
F: FnMut(&mut T) -> bool;
196202

197-
#[inline]
198-
pub unsafe fn set_len(&mut self, len: usize);
199-
200-
pub fn splice<R, I>(&mut self, range: R, replace_with: I)
201-
where
202-
I: IntoIterator<Item = T>,
203-
R: RangeBounds<usize>;
203+
pub fn splice<I, R>(&mut self, range: R, replace_with: I) -> Option<Splice<'_, I::IntoIter, N>>;
204204

205-
pub fn split_off(&mut self, at: usize) -> Self;
205+
pub fn split_off(&mut self, at: usize) -> Option<Self>;
206206

207+
#[inline]
207208
pub fn swap_remove(&mut self, idx: usize) -> Option<T>;
208209

209-
pub fn truncate(&mut self, len: usize);
210+
#[inline]
211+
pub const fn truncate(&mut self, len: usize);
210212
}
211213
```
212214

@@ -287,7 +289,7 @@ The above description is very similar to what `smallvec` already does.
287289
Many structures that use `alloc::vec::Vec` as the underlying storage can also use stack or hybrid memory, for example, an hypothetical `GenericString<S>`, where `S` is the storage, could be split into:
288290

289291
```rust
290-
type DynString = GenericString<DynVec<u8>>;
292+
type DynString<const N: usize> = GenericString<DynVec<u8, N>>;
291293
type HeapString = GenericString<Vec<u8>>;
292-
type StackString = GenericString<ArrayVec<u8>>;
294+
type StackString<const N: usize> = GenericString<ArrayVec<u8, N>>;
293295
```

0 commit comments

Comments
 (0)