use crate::Stack;
use std::ptr;
impl<V: Copy, const N: usize> Clone for Stack<V, N> {
#[must_use]
fn clone(&self) -> Self {
let mut s: Self = Self::new();
s.next = self.next;
unsafe { ptr::copy::<V>(self.items.as_ptr(), s.items.as_mut_ptr(), s.next) };
s
}
}
#[test]
fn stack_can_be_cloned() {
let mut s: Stack<u8, 16> = Stack::new();
unsafe { s.push_unchecked(42) };
assert_eq!(42, s.clone().pop());
}
#[test]
fn full_stack_can_be_cloned() {
let mut s: Stack<usize, 16> = Stack::new();
for i in 0..s.capacity() {
unsafe { s.push_unchecked(i) };
}
assert_eq!(s.capacity() - 1, s.clone().pop());
}
#[test]
fn empty_stack_can_be_cloned() {
let m: Stack<u8, 0> = Stack::new();
assert!(m.clone().is_empty());
}