This Rust program creates some strings containing formatted data. It then copies these strings to a byte vector and prints the vector the console.
fn main() {
// Part 1: use format macro with an integer and an array.
let value = 10;
let value2 = [1, 2, 3];
let result = format!(
"Value is {} and value2 is {:?}", value, value2);
println!(
"{}", result);
// Part 2: use concat macro with constants.
let result2 = concat!(
"Value is ", 100,
" and value2 is ", 200);
println!(
"{}", result2);
// Part 3: copy the results to a byte vector.
let mut copy = vec![];
copy.extend_from_slice(result.as_bytes());
copy.extend_from_slice(b
"...");
copy.extend_from_slice(result2.as_bytes());
println!(
"{}", String::from_utf8_lossy(©).to_string());
}
Value is 10 and value2 is [1, 2, 3]
Value is 100 and value2 is 200
Value is 10 and value2 is [1, 2, 3]...Value is 100 and value2 is 200