Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft: Overly restricted/constrained lifetimes #77

Merged
merged 1 commit into from
Feb 7, 2024

Conversation

arifd
Copy link
Contributor

@arifd arifd commented Feb 6, 2024

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

@arifd arifd changed the title Draft: Overly restricted/constrained lifetime Draft: Overly restricted/constrained lifetimes Feb 6, 2024
@mdecimus
Copy link
Member

mdecimus commented Feb 7, 2024

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.

@mdecimus mdecimus marked this pull request as ready for review February 7, 2024 12:47
@mdecimus mdecimus merged commit cf87d35 into stalwartlabs:main Feb 7, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants