-
Notifications
You must be signed in to change notification settings - Fork 9
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
Mixed consuming/mutable reference access to RulesetCreated::add_rule
#19
Conversation
Signed-off-by: Andrea Venuta <andrea@phylum.io>
Signed-off-by: Andrea Venuta <andrea@phylum.io>
Signed-off-by: Andrea Venuta <andrea@phylum.io>
Signed-off-by: Andrea Venuta <andrea@phylum.io>
2552454
to
0834f81
Compare
Hi! Just wanted to follow up on this. Are the changes in this PR something you'd be interested in integrating upstream? We're considering releasing our abstraction project on crates.io. At the moment it relies on our fork, but we'd like to use an official release as we won't be able to publish the crate otherwise. Again, thank you for your work! |
Hi @andreaphylum! Thanks for your PR. I've been busy and didn't want to rush this review, but I'll do it next week. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the code, it is clean and well split, but I think we can do simpler with #20. What do you think?
/// | ||
/// drop(ruleset); | ||
/// ``` | ||
pub fn as_mut(&mut self) -> RulesetCreatedMut<'_> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as_mut()
is the same as the one provided by the AsMut
trait, but it is not the same signature. I think it is not a good idea.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed, this was an unfortunate compromise I had to settle upon eventually, as implementing AsMut
had some issues that made the rest of the code significantly more convoluted and need many more workarounds.
This enables to make add_rule(), add_rules() and set_no_new_privs() available from a RulesetCreated reference. Users need to import the RulesetCreatedRef trait to call such methods. Closes landlock-lsm#19 Signed-off-by: Mickaël Salaün <mic@digikod.net>
This enables to make add_rule(), add_rules() and set_no_new_privs() available from a RulesetCreated reference. Implement AsMut<RulesetCreated>, required by RulesetCreatedAttr. Users need to import the RulesetCreatedAttr trait to call such methods. Closes landlock-lsm#19 Signed-off-by: Mickaël Salaün <mic@digikod.net>
This enables to make add_rule(), add_rules() and set_no_new_privs() available from a RulesetCreated reference. Implement AsMut<RulesetCreated>, required by RulesetCreatedAttr. Users need to import the RulesetCreatedAttr trait to call such methods. Closes landlock-lsm#19 Signed-off-by: Mickaël Salaün <mic@digikod.net>
This enables to make add_rule(), add_rules() and set_no_new_privs() available from a RulesetCreated reference. Implement AsMut<RulesetCreated>, required by RulesetCreatedAttr. Users need to import the RulesetCreatedAttr trait to call such methods. Closes landlock-lsm#19 Signed-off-by: Mickaël Salaün <mic@digikod.net>
This patch takes the ideas discussed in #16 and implements a wrapper type,
RulesetCreatedMut
(following the standard library convention of usingMut
to refer to mutable references, e.g.AsMut
vs.AsRef
).RulesetCreated::as_mut
method is created, which returns an instance of the newtype.RulesetCreatedMut::add_rule
andRulesetCreatedMut::add_rules
methods, and are called by the original methods viaas_mut()
before returningself
.set_no_new_privs
method is copied over, as it is a one-liner.This should hopefully not be a breaking change for other dependents of
rust-landlock
, as the consuming API is left intact.Having to explicitly go through
as_mut
to access the non-consuming methods might not be super intuitive, but I think it is a good, low-impact compromise.There's still the issue of having to maintain duplicated methods going forward, but I believe that in order to implement any future method on the consuming side it would be enough to do a trivial call to the non-consuming side.
Thank you for your work on
rust-landlock
!