rustHow do I create an array of strings in Rust?
Creating an array of strings in Rust is a simple task. To do so, you can use the vec!
macro. This macro takes a list of values and creates a vector from them. For example, the following code creates an array of strings:
let array_of_strings = vec!["Hello", "World"];
The vec!
macro creates a Vec<T>
type, which is a vector of type T
. In this case, T
is a &str
, which is a string slice. The vec!
macro takes a list of values and creates a vector from them.
The output of the example code is a Vec<&str>
type, which is a vector of string slices:
[Hello, World]
For more information, see the Rust documentation on vectors.
More of Rust
- How to get a capture group using Rust regex?
- How to convert a u8 slice to a hex string in Rust?
- How to use regex with bytes in Rust?
- How to get the length of a Rust HashMap?
- How to match the end of a line in a Rust regex?
- How to create a HashMap of HashMaps in Rust?
- How to convert the keys of a Rust HashMap to a vector?
- How to convert a Rust HashMap to a BTreeMap?
- How do I use a variable from another file in Rust?
- How to declare a matrix in Rust?
See more codes...