streambed / streambed-rs

Event driven services toolkit
Apache License 2.0
32 stars 5 forks source link

Why is offsets in scoped_subscribe an Option<Vec<ConsumerOffset>> #17

Closed hseeberger closed 2 years ago

hseeberger commented 2 years ago

Why not drop the Option? Ain't None and Some(Vec::empty) the same?

huntc commented 2 years ago

Not the same when serialised… it is the diff between a json field having an empty array and the fuels not being present.

hseeberger commented 2 years ago

But is there a semantic difference at the level of Rust code? If not, i.e. if both None and Some(Vec::empty) lead to the program behaving the same way, it would simplify the API if we removed the option and made any needed adjustments for serialization.

huntc commented 2 years ago

Actually, I don't think there is a Vec::empty function is there? Doesn't the creation of an empty vector always allocate?

hseeberger commented 2 years ago

Sorry, that was just me using Rust like pseudo code.

If you create an empty Vec, e.g. via Vec::new or Vec![], then its capacity is set to zero and it does not allocate heap memory. See https://doc.rust-lang.org/std/vec/struct.Vec.html#guarantees.

Not sure though how the serialization code creates Vecs.

huntc commented 2 years ago

You're right. I shall change it.