History

feat: `Permissions::check_opt()` for those who don't need an error case. (#450)

Sebastian Thiel committed 4 years ago

Commit 515e5211 parent ac3823d2 files · +27 −0Browse files

Showing the changes to git-sec/src (1 of 2 files). Show all

Unified · Split

git-sec/src/permission.rs+9−0
@@ -28,6 +28,15 @@ impl Permission { · 27 unmodified lines
2828 }),
2929 }
3030 }
31+
32+ /// Like [`check()`][Self::check()], but degenerates the type to an option to make it more useful in cases where
33+ /// `Forbid` shoudn't abort the entire operation.
34+ pub fn check_opt<R: std::fmt::Debug>(&self, resource: R) -> Option<R> {
35+ match self {
36+ Permission::Allow => Some(resource),
37+ Permission::Deny | Permission::Forbid => None,
38+ }
39+ }
3140 }
3241
3342 impl Display for Permission {