Issue
I'm playing with Rust and I wonder how I can print an array and a vector.
let a_vector = vec![1, 2, 3, 4, 5];
let an_array = ["a", "b", "c", "d", "e"];
I want to print on the screen and the result should be something like:
[1, 2, 3, 4, 5]
["a", "b", "c", "d", "e"]
In python it is:
lst = ["a", "b", "c", "d", "e"]
print lst
and printing it would show:
["a", "b", "c", "d", "e"]
Solution
println!("{:?}", a_vector);
println!("{:?}", an_array);
The {:?}
is used to print types that implement the Debug trait. A regular {}
would use the Display trait which Vec and arrays don't implement.
Answered By - A.B. Answer Checked By - Terry (PHPFixing Volunteer)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.