From 37ccc54bd2c2f1fadb3b5adb003d123ceb80d535 Mon Sep 17 00:00:00 2001 From: Caio Date: Fri, 9 Oct 2020 09:11:13 -0300 Subject: [PATCH] Tweak methods --- text/2978-stack_based_vec.md | 52 +++++++++++++++++++----------------- 1 file changed, 27 insertions(+), 25 deletions(-) diff --git a/text/2978-stack_based_vec.md b/text/2978-stack_based_vec.md index e52d9974ec5..202c9e7d66a 100644 --- a/text/2978-stack_based_vec.md +++ b/text/2978-stack_based_vec.md @@ -125,10 +125,10 @@ impl ArrayVec { // 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; @@ -136,13 +136,13 @@ impl ArrayVec { // 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]; @@ -150,63 +150,65 @@ impl ArrayVec { #[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(&mut self, same_bucket: F) where F: FnMut(&mut T, &mut T) -> bool; - pub fn dedup_by_key(&mut self, key: F) + pub fn dedup_by_key(&mut self, mut key: F) where F: FnMut(&mut T) -> K, K: PartialEq; - pub fn drain(&mut self, range: R) + pub fn drain(&mut self, range: R) -> Option> where R: RangeBounds; - 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; #[inline] pub fn push(&mut self, element: T) -> Result<(), T>; + #[inline] pub fn remove(&mut self, idx: usize) -> Option; - pub fn retain(&mut self, f: F) + pub fn retain(&mut self, mut f: F) where F: FnMut(&mut T) -> bool; - #[inline] - pub unsafe fn set_len(&mut self, len: usize); - - pub fn splice(&mut self, range: R, replace_with: I) - where - I: IntoIterator, - R: RangeBounds; + pub fn splice(&mut self, range: R, replace_with: I) -> Option>; - pub fn split_off(&mut self, at: usize) -> Self; + pub fn split_off(&mut self, at: usize) -> Option; + #[inline] pub fn swap_remove(&mut self, idx: usize) -> Option; - pub fn truncate(&mut self, len: usize); + #[inline] + pub const fn truncate(&mut self, len: usize); } ``` @@ -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`, where `S` is the storage, could be split into: ```rust -type DynString = GenericString>; +type DynString = GenericString>; type HeapString = GenericString>; -type StackString = GenericString>; +type StackString = GenericString>; ```