Showing the changes to git-sec/src (1 of 2 files). Show all
Unified · Split
| @@ -28,6 +28,15 @@ impl Permission { · 27 unmodified lines | |||
| 28 | }), | 28 | }), |
| 29 | } | 29 | } |
| 30 | } | 30 | } |
| 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 | } | ||
| 31 | } | 40 | } |
| 32 | 41 | ||
| 33 | impl Display for Permission { | 42 | impl Display for Permission { |