Rust array string to array string literal

So I have a array of strings and I want to know how can I make it on array of string literals

It's not clear what you are trying to do. In what form do you have the strings? Do you mean you have a [String; N] value? What do you mean by "make it on array of string literals"?

so first at first I had a vec of strings and I did &*vec and it gave me a [String] but I need to now get a &[&str]

You can do that by creating a new vector, then:

let original: Vec<String> = …;
let slices: Vec<&str> = original.iter().map(AsRef::as_ref).collect();

However, the string slices in the new vector won't be string literals. A literal &str is a string constant spelled out in the source code. The correct general name for the &str type is "string slice".


This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.