stalwartlabs / mail-parser

Fast and robust e-mail parsing library for Rust
https://docs.rs/mail-parser/
Apache License 2.0
289 stars 39 forks source link

Draft: Overly restricted/constrained lifetimes #77

Closed arifd closed 7 months ago

arifd commented 7 months ago

Some places take in &'x self when they shouldn't.

The functions returning iterators, probably need two lifetimes, so that they don't bind the lifetime associated with the input buffer, to self.

But I need a bit more time to play with the code.

Discussion in the discord forums is telling me that some functions, like this one:

body_html(&'x self, pos: usize) -> Option<Cow<'x, str>> 

Could maybe return an Option<Cow<'_, Cow<'x, str>>> Which looks a little crazy to me tbh, but i'm told:

It prevents the need to clone the String if it's not needed

mdecimus commented 7 months ago

Could maybe return an Option<Cow<'_, Cow<'x, str>>> Which looks a little crazy to me tbh, but i'm told: It prevents the need to clone the String if it's not needed

Not sure what they meant by that. Cow is used in the code specifically to avoid allocating memory when it is not needed.