use super::GenericVec; use crate::{ error::FullError, traits::{DefaultContainer, Length}, }; use core::iter::IntoIterator; impl GenericVec { /// Create a new empty vector. pub fn new() -> Self { unsafe { Self::from_raw_parts(C::default(), L::zero()) } } } impl GenericVec { pub fn from_iter_until_full>(iter: I) -> Self { let mut self_ = Self::new(); self_.extend_until_full(iter); self_ } } impl Default for GenericVec { fn default() -> Self { Self::new() } } impl Clone for GenericVec where C::Item: Clone, { fn clone(&self) -> Self { Self::try_from_slice(self.as_slice()).unwrap() } } impl GenericVec where C::Item: Clone, { /// Creates a new vector with cloned elements from slice. /// /// If slice length is greater than the vector capacity then error is returned. pub fn try_from_slice(slice: &[C::Item]) -> Result { let mut self_ = Self::default(); self_.push_slice(slice)?; Ok(self_) } } impl TryFrom<&[C::Item]> for GenericVec where C::Item: Clone, { type Error = FullError; fn try_from(slice: &[C::Item]) -> Result { Self::try_from_slice(slice) } }