Function std::vec::as_vec
[−]
[src]
pub fn as_vec<T>(x: &'a [T]) -> DerefVec<'a, T>
Unstable
Converts a slice to a wrapper type providing a &Vec<T>
reference.
Examples
#![feature(collections)] fn main() { use std::vec::as_vec; // Let's pretend we have a function that requires `&Vec<i32>` fn vec_consumer(s: &Vec<i32>) { assert_eq!(s, &[1, 2, 3]); } // Provide a `&Vec<i32>` from a `&[i32]` without allocating let values = [1, 2, 3]; vec_consumer(&as_vec(&values)); }use std::vec::as_vec; // Let's pretend we have a function that requires `&Vec<i32>` fn vec_consumer(s: &Vec<i32>) { assert_eq!(s, &[1, 2, 3]); } // Provide a `&Vec<i32>` from a `&[i32]` without allocating let values = [1, 2, 3]; vec_consumer(&as_vec(&values));