November 2017
Intermediate to advanced
264 pages
5h 45m
English
The write! macro allows you to write values into any kind of buffer, optionally using the same formatting capabilities as format! and println!. In the following example, we simply write a string to a vector:
// from Chapter 8/code/write.rs
// in order to be able to use write! on a vector
use std::io::Write;
fn main() {
let mut vec1 = Vec::new();
write!(&mut vec1, "test");
println!("{:?}", vec1);
}
This prints out the following:
[116, 101, 115, 116].
A handy macro during development is unimplemented!, which you might have already seen in generated code. You can also use it yourself as a temporary placeholder for a function body you will write later:
// from Chapter 8/code/unimplemented.rs fn main() { unimplemented!(); ...Read now
Unlock full access