devela::data::collections

Trait ExtVec

Source
pub trait ExtVec<T>: Sealed {
    // Required methods
    fn vec_into_vec<U>(self) -> Vec<U> 
       where U: From<T>;
    fn vec_try_into_vec<E, U>(self) -> Result<Vec<U>, E> 
       where U: TryFrom<T, Error = E>;
}
Available on crate feature alloc only.
Expand description

Extension trait providing additional methods for Vec.

This trait is sealed and cannot be implemented for any other type.

Required Methods§

Source

fn vec_into_vec<U>(self) -> Vec<U>
where U: From<T>,

Converts Vec<T> to Vec<U> when U implements From<T>.

§Examples
assert_eq![vec![1_u16, 2, 3], vec![1_u8, 2, 3].vec_into_vec::<u16>()];
assert_eq![vec![1_u16, 2, 3], vec![1_u8, 2, 3].vec_into_vec::<u16>()];
Source

fn vec_try_into_vec<E, U>(self) -> Result<Vec<U>, E>
where U: TryFrom<T, Error = E>,

Tries to convert Vec<T> to Vec<U> when U implements TryFrom<T>.

§Examples
assert_eq![Ok(vec![1_i32, 2, 3]), vec![1_i64, 2, 3].vec_try_into_vec()];
assert_eq![Ok(vec![1_i32, 2, 3]), vec![1_i64, 2, 3].vec_try_into_vec::<_, i32>()];

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<T> ExtVec<T> for Vec<T>