prost
prost copied to clipboard
Is there a way to provide repeated fields as iterator rather than Vec?
I have a message that contains a repeated list of things:
message Packet {
String id = 1;
repeated Thing things = 2;
}
When generated, I get a struct which looks something like:
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct Packet {
#[prost(message, optional, tag="1")]
pub id: ::core::option::Option<String>,
#[prost(message, repeated, tag="2")]
pub things: ::prost::alloc::vec::Vec<Thing>,
}
This is fine for decoding - I always need to allocate memory for a Vec while decoding anyway.
However, for encoding, is it possible to provide an iterator instead of a Vec and entirely avoid the Vec allocation?
Unfortunately, a Vec is required. Supporting generic iterators is quite hard to support I believe.