Use a Vector as a Writer in Rust
To write to a vector, using the std::io::Write
-trait, you need to pass a & mut
– a mutable reference – of the vector where you need the writer.
If you just pass the vector, it gets moved into the function. A reference doesn't implement the std::io::Write
-trait.
In code:
use plist::Value; // I am using the plist crate as an example
let mut buf = Vec::new(); // creating the backing vector
let dic = Value::Dictionary(body); // just to get the correct type
dic.to_writer_binary(&mut buf); // pass the &mut of the vector
Read other posts