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

Remove MutVecInput and MappedInput in Favour of Impls on References #2783

Merged
merged 8 commits into from
Dec 19, 2024

Conversation

riesentoaster
Copy link
Contributor

Turns out implementing the required traits directly on the borrows is possible and much cleaner.

This also allows removing MappedInput, which caused significant headaches for mapping mutators.

@riesentoaster riesentoaster changed the title Remove MutVecInput and MappedInput Remove MutVecInput and MappedInput in Favour of Impls on References Dec 18, 2024
self.as_mut()
}

fn resize(&mut self, new_len: usize, value: u8) {
Copy link
Member

Choose a reason for hiding this comment

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

Doesn't this make using Vec a bit of a headache whenever HasMutatorBytes is in scope?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If, in the same file, one has HasMutatorBytes in scope and uses any of the duplicate functions on a Vec<u8> specifically, one would need to specify which implementation to use. Since one just forwards to the other, you can't really choose wrong, it's just annoying to write the extra code.

@@ -36,28 +36,28 @@ impl Input for CustomInput {

impl CustomInput {
/// Returns a mutable reference to the byte array
pub fn byte_array_mut(&mut self) -> MutVecInput<'_> {
(&mut self.byte_array).into()
pub fn byte_array_mut(&mut self) -> &mut Vec<u8> {
Copy link
Member

Choose a reason for hiding this comment

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

Nice!

@domenukk
Copy link
Member

Amazing, think we're almost there now! :) Much clener than before

@riesentoaster
Copy link
Contributor Author

riesentoaster commented Dec 19, 2024

Careful, there's a difference between the mutators themselves (MappingMutator and OptionalMutator) and the structs that allow mapping them over a tuple_list (ToMappingMutatorMapper and ToOptionalMutatorMapper), since they need to have different data.

Edit: Ah, wait. I misread. I don't really like those names tbh, I think they should at least have the word Mutator or Mutating in them. But how about something like ToOptionalMutator and ToMappingMutator? Just drop the Mapper in the end?

@domenukk
Copy link
Member

Sounds good. Anything shorter is good :)

@domenukk domenukk merged commit 5d70216 into AFLplusplus:main Dec 19, 2024
103 checks passed
@riesentoaster riesentoaster deleted the newtype-mutvecinput branch December 19, 2024 13:51
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