I'd like to create a method that accepts a Vec of values that all implement
serde::ser::Serializable. (The method iterates over the vec, serializes each value to bytes, and writes the bytes to disk).
Is there any way to do this? In Java/Typescript/etc. there might be an interface that all the objects could implement.
Normally, I would create a
trait with a method called
to_bytes or something like that, but in this case I want to directly pass each value,
rmp_serde::encode::write_named(&mut writer, x) b/c I want to serialize the values directly to the file (avoid intermediate allocations / copies).
I tried making the parameter
vals: Vec<Box<dyn serde::ser::Serialize>>, but that didn't work.