Cookbook
1. Convert Vec<String> to Vec<&str>
fn main() { let v: Vec<String> = vec![String::from("john"), String::from("doe")]; let mut v_ref = Vec::<&str>::with_capacity(v.len()); for item in &v { v_ref.push(item); } }
Press ← or → to navigate between chapters
Press S or / to search in the book
Press ? to show this help
Press Esc to hide this help
fn main() { let v: Vec<String> = vec![String::from("john"), String::from("doe")]; let mut v_ref = Vec::<&str>::with_capacity(v.len()); for item in &v { v_ref.push(item); } }