Skip to content

feat(managed): Add logic so retain can be used both on vec and smallvec#5753

Draft
tobias-wilfert wants to merge 1 commit intomasterfrom
tobias-wilfer/feat/add-helper-trait
Draft

feat(managed): Add logic so retain can be used both on vec and smallvec#5753
tobias-wilfert wants to merge 1 commit intomasterfrom
tobias-wilfer/feat/add-helper-trait

Conversation

@tobias-wilfert
Copy link
Copy Markdown
Member

While working on #5747 I would ideally have something like this irregardles of if attachments are a vec or a smallvec (items):

pub fn validate(attachments: &mut Managed<SerializedAttachments>) {
    attachments.retain(
        |attachments| &mut attachments.attachments,
        |attachment, _| utils::attachments::validate(attachment),
    );
}

Comment on lines +169 to +176
fn retain_mut(&mut self, f: impl FnMut(&mut I) -> bool) {
Vec::retain_mut(self, f);
}
}
impl<I, const N: usize> RetainMut<I> for SmallVec<[I; N]> {
fn retain_mut(&mut self, f: impl FnMut(&mut I) -> bool) {
SmallVec::retain_mut(self, f);
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Make explicit that the wrapper and the underlying function have the same return type.

Suggested change
fn retain_mut(&mut self, f: impl FnMut(&mut I) -> bool) {
Vec::retain_mut(self, f);
}
}
impl<I, const N: usize> RetainMut<I> for SmallVec<[I; N]> {
fn retain_mut(&mut self, f: impl FnMut(&mut I) -> bool) {
SmallVec::retain_mut(self, f);
}
fn retain_mut(&mut self, f: impl FnMut(&mut I) -> bool) {
Vec::retain_mut(self, f)
}
}
impl<I, const N: usize> RetainMut<I> for SmallVec<[I; N]> {
fn retain_mut(&mut self, f: impl FnMut(&mut I) -> bool) {
SmallVec::retain_mut(self, f)
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants