Skip to content

Commit

Permalink
Tweak methods
Browse files Browse the repository at this point in the history
  • Loading branch information
c410-f3r committed Oct 9, 2020
1 parent b50e3f7 commit 37ccc54
Showing 1 changed file with 27 additions and 25 deletions.
52 changes: 27 additions & 25 deletions text/2978-stack_based_vec.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,88 +125,90 @@ impl<T, const N: usize> ArrayVec<T, N> {
// Constructors

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

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

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

// Methods

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

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

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

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

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

pub fn clear(&mut self);
#[inline]
pub const fn clear(&mut self);

pub fn dedup(&mut self);
pub fn dedup(&mut self)
where
T: PartialEq;

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

pub fn dedup_by_key<F, K>(&mut self, key: F)
pub fn dedup_by_key<F, K>(&mut self, mut key: F)
where
F: FnMut(&mut T) -> K,
K: PartialEq<K>;

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

pub fn extend_from_cloneable_slice(&mut self, other: &[T]) -> Result<(), &[T]>
pub fn extend_from_cloneable_slice<'a>(&mut self, other: &'a [T]) -> Result<(), &'a [T]>
where
T: Clone;

pub fn extend_from_copyable_slice(&mut self, other: &[T]) -> Result<(), &[T]>

pub fn extend_from_copyable_slice<'a>(&mut self, other: &'a [T]) -> Result<(), &'a [T]>
where
T: Copy;

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

#[inline]
pub const fn is_empty(&self) -> bool;

#[inline]
pub const fn len(&self) -> usize;


#[inline]
pub fn pop(&mut self) -> Option<T>;

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

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

pub fn retain<F>(&mut self, f: F)
pub fn retain<F>(&mut self, mut f: F)
where
F: FnMut(&mut T) -> bool;

#[inline]
pub unsafe fn set_len(&mut self, len: usize);

pub fn splice<R, I>(&mut self, range: R, replace_with: I)
where
I: IntoIterator<Item = T>,
R: RangeBounds<usize>;
pub fn splice<I, R>(&mut self, range: R, replace_with: I) -> Option<Splice<'_, I::IntoIter, N>>;

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

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

pub fn truncate(&mut self, len: usize);
#[inline]
pub const fn truncate(&mut self, len: usize);
}
```

Expand Down Expand Up @@ -287,7 +289,7 @@ The above description is very similar to what `smallvec` already does.
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:

```rust
type DynString = GenericString<DynVec<u8>>;
type DynString<const N: usize> = GenericString<DynVec<u8, N>>;
type HeapString = GenericString<Vec<u8>>;
type StackString = GenericString<ArrayVec<u8>>;
type StackString<const N: usize> = GenericString<ArrayVec<u8, N>>;
```

0 comments on commit 37ccc54

Please sign in to comment.