prost icon indicating copy to clipboard operation
prost copied to clipboard

Is there a way to provide repeated fields as iterator rather than Vec?

Open sunpeaksfivemile opened this issue 3 years ago • 1 comments

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?

sunpeaksfivemile avatar Aug 15 '22 22:08 sunpeaksfivemile

Unfortunately, a Vec is required. Supporting generic iterators is quite hard to support I believe.

LucioFranco avatar Aug 16 '22 16:08 LucioFranco