/build/source/src/execution/assert_validated.rs
Line | Count | Source (jump to first uncovered line) |
1 | | //! Helpers for assertions due to prior validation of a WASM program. |
2 | | |
3 | | use core::fmt::Debug; |
4 | | |
5 | | pub(crate) trait UnwrapValidatedExt<T> { |
6 | | fn unwrap_validated(self) -> T; |
7 | | } |
8 | | |
9 | | impl<T> UnwrapValidatedExt<T> for Option<T> { |
10 | | /// Indicate that we can assume this Option to be Some(_) due to prior validation |
11 | 313k | fn unwrap_validated(self) -> T { |
12 | 313k | self.expect("Validation guarantees this to be `Some(_)`, but it is `None`") |
13 | 313k | } |
14 | | } |
15 | | |
16 | | impl<T, E: Debug> UnwrapValidatedExt<T> for Result<T, E> { |
17 | | /// Indicate that we can assume this Result to be Ok(_) due to prior validation |
18 | 157k | fn unwrap_validated(self) -> T { |
19 | 157k | self.unwrap_or_else(|e| { |
20 | 0 | panic!("Validation guarantees this to be `Ok(_)`, but it is `Err({e:?})`"); |
21 | 157k | }) |
22 | 157k | } |
23 | | } |
24 | | |
25 | | #[macro_export] |
26 | | macro_rules! unreachable_validated { |
27 | | () => { |
28 | | unreachable!("because of prior validation") |
29 | | }; |
30 | | } |