std-function

std::array::from_ref

Borrow a single existing value as a length-one array. No copy is required; the returned reference is tied to the input borrow. Expected stdout (not executed): Ada Common mistake: Expecting the returned array reference to outlive the input.

Formal Syntax & Structure

rust syntaxrust
std::array::from_ref(&value) -> &[T; 1]

Working Example

Example Snippetrust
fn main() {    let name = String::from("Ada");    let one = std::array::from_ref(&name);    println!("{}", one[0]);}
Rust Reference