# 0.3.4 # 0.3.3 ## New features * New method: `Stack::truncate`, a conventient way to shorten the size of the stack. * New method: `Stack::apply_tos`, apply a user-defined function to TOS in order to change it in place instead of popping, applying and pushing back. * Now you can iterate from top to bottom of a `Stack` with the `StackIntoIter` struct. This is more good-looking than writing `while let Some(item) = stack.pop() { /* code */ }`. * `impl TryFrom> for Stack`, create a `Stack` from a `Vec` which must have its length `<=` than the stack's capacity. Otherwise, the function returns a `StackError`. The implementation is gated behind the `std` feature. ## Breaking changes * The `replace_` methods have been renamed to `swap_` because I like it better and reminds me more of the `swap` function in the stdlib. * Removed `Eq` implementation: it does not make sense to implement it! ## Other changes * Fixed a bug in the `Debug` implementation of `Stack`. Not it works correctly. # 0.3.2 ## Other changes * Fixed a bug where the `truncate` method would cause UB under certain scenarios. * The behavior of `truncate` has been modified and now it behaves like `Vec::truncate`. # 0.3.1 ## Internal changes * Fixed docs typos. # 0.3.0 ## Breaking changes * `EmptyStackError`, `StackOverflowError` and `UnderfullStackError` have been replaced by the `StackError` enum. The `enum` has two variants: `Underflow` (too few items to perform the requested operations) and `Overflow` (too many items to perform the requested operation). `StackError` optionally implements `std::error::Error` if the `std` feature is enabled. ## New features * Optional `std` feature: enables some trait implementations only available with the `std` library. The feature is disabled by default. * New method: `extend`, allows to add items from an `IntoIterator`. ```rust fn main() { let odd_numbers = (0..10).filter(|x| x % 2 != 0); let mut stack = stack![i32; 20]; stack.extend(odd_numbers).unwrap(); assert_eq!(stack, [1, 3, 5, 7, 9]); // Same as the following // for number in odd_numbers { // stack.push(number).unwrap(); // } } ``` * New method: `extend_array`, a specialized implementation of `extend`. The method accepts an `arr: [T; M]` and inserts the items of `arr` into the stack. * New method: `cut`, removes `M` items from the stack and returns them as a `[T; M]`. No allocation is involved. * New method: `truncate`, removes `len` items from the stack and drops them. * `Stack` now implements the following traits: - `PartialEq> where T: PartialEq` - `PartialEq<[U; N]> where T: PartialEq` - `PartialEq<[U]> where T: PartialEq` - `PartialEq<&[U]> where T: PartialEq` The old `PartialEq> where T: PartialEq` was removed. The new trait implementations allow for the following code to be compiled and executed, while it previously could not. This allows for better debugging and checking stack identity (previously, you had to create a new stack and compare both of them). ```rust fn main() { let stack = stack! { [String; 10] = [ "This!".to_string(), "is!".to_string(), "awesome!".to_string() ] }; assert_eq!(stack, [ "This!".to_string(), "is!".to_string(), "awesome!".to_string() ]); // String implements PartialEq<&str> assert_eq!(stack, ["This!", "is!", "awesome!"]); // Even with slices! assert_eq!(stack, &["This!", "is!", "awesome!"][..]); } ``` ## Other changes * Now all the methods used by `Stack` are `#[inline]`. Previously, only some of them were inlined. * The `Debug` implementation for `Stack` is now a bit faster thanks to no bound checking for already initialized items. * The `Hash` implementation for `Stack` is now faster as the raw ptr to the init items is hashed instead of the items themselves * The `Clone` trait bound implementation for `Stack` has been relaxed (from `T: Copy` to `T: Clone`). ## Internal changes * `init_items_as_ptr` and `init_items_as_ptr_mut` now take an argument `start: usize` to define the beginning index of the initialized items to return as raw pointer. * `drop_impl` was renamed to `drop_items` and now take an argument `start: usize`. The items `[start..self.len]` will be dropped. Note that `drop_items` does not reset `self.len`: it just drops items. # 0.2.1 # Other changes * Fixed typos in README. # 0.2.0 Released: 19/09/2023 ## Breaking changes * The `count` method was renamed to `len` for consistency. ## New features * Added `_panicking` methods for `push`, `pop`, `tos`, `tos_mut`: these methods panic if the safety requirements are not met, rather than returning `Err` or causing UB. * Added `replace_tos`, `replace_tos_panicking`, `replace_tos_unchecked`: these methods allow the user to swap TOS with the provided `item` argument. * Added `EmptyStackError`: returned by `replace_tos` if the stack is empty. Note that `pop` returns `None` if the stack is empty due to consistency. * Added `rotate_tos`, `rotate_tos_panicking`, `rotate_tos_unchecked`: these methods allow the user to swap TOS with TOS - 1. * Added `UnderfullStackError`: returned by `rotate_tos` if the stack contains less than 2 items. * Added `Stack::capacity` to get the number of items the stack can hold. * Added `impl code::hash::Hash for Stack where T: core::hash::Hash`. # Other changes * Rewritten part of the docs. * Changed licence from MIT to MIT or Apache 2.0. # Internal changes * Created macro `stack_errors!` to create multiple stack related errors avoiding boilerplate code to be written. * Added `init_items_as_ptr` and `init_items_as_ptr_mut` to cast `[mem::MaybeUninit; N]` to `*const [T]` or `*mut [T]` with a function rather than copy paste.