jamesmunns / postcard

A no_std + serde compatible message library for Rust
Apache License 2.0
930 stars 89 forks source link

Consider splitting `try_take_n` on `de_flavors::Flavor` #93

Open jamesmunns opened 1 year ago

jamesmunns commented 1 year ago

Right now, we don't really distinguish between cases where we want to take N bytes from the stream because we might want to borrow the data (e.g. for zero-copy &'de str or &'de [u8] cases), and where we just happen to know we want the next N bytes in the stream (e.g. the current deserializers for f32, f64, and char).

While discussing an "interning flavor" with @cr1901, I realized that the approach I took in this proof of concept would inadvertently intern bytes for the f32/f64/char types as well, even though these only need to be "transient" borrows.

It might be worth it to add a new default trait method, like try_take_n_transient, which defaults to passing through to try_take_n, to allow flavors that care to distinguish between these kinds of takes.

Could be relevant to #91.

cr1901 commented 1 year ago

Would it be worth adding a reworked Interner flavor from that gist you made to postcard proper in the future?

(I didn't get to work on tailoring it to my needs today, sorry!)

jamesmunns commented 1 year ago

Yeah, I think it could make sense. It might be reusable by this and the IO stuff.

Not sure yet though, I need to actually do a more in depth look at pr91 first, to see if that matches what they were doing.