push, insert
etc
With the goal of making arrayvec more of a "drop-in" for Vec, we realign the signatures methods .push(elt), .insert(index, elt)
and .remove(index)
.
pub fn push(&mut self, element: A::Item);
pub fn insert(&mut self, index: usize, element: A::Item);
pub fn remove(&mut self, index: usize) -> A::Item;
pub fn swap_remove(&mut self, index: usize) -> A::Item;
try_push
etc
Mimicing something like fallible allocation, we have the fallible new methods:
pub fn try_push(&mut self, element: A::Item) -> Result<(), CapacityError<A::Item>>;
pub fn try_insert(&mut self, index: usize, element: A::Item) -> Result<(), CapacityError<A::Item>>;
Notice that try_insert
still panics if index
is out of bounds.
pop_at
etc
Mimicing .pop()
, we have new “checked” versions of remove, swap_remove
:
pub fn pop_at(&mut self, index: usize) -> Option<A::Item>;
pub fn swap_pop(&mut self, index: usize) -> Option<A::Item>;
The rationale is: indexing out of bounds is not a regular runtime error, it's normally a contract violation. So when we introduce checked versions of such API, then we get “checked” versions that return Option
. Non-presence is not necessarily an error.
ArrayString::push
etc
- ArrayString: push, push_str now have the same signature as corresponding on String. New methods try_push, try_push_str.
pub fn push(&mut self, c: char);
pub fn try_push(&mut self, c: char) -> Result<(), CapacityError<char>>;
pub fn push_str(&mut self, s: &str);
pub fn try_push_str<'a>(&mut self, s: &'a str) -> Result<(), CapacityError<&'a str>>;
Closes #46
Closes #45
Miscellaneous Changes
- odds is no longer a public dependency. We want the flexibility of dropping/upgrading this dep at will
- Rust version changes