Coverage Report

Created: 2024-09-10 12:50

/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
14.7k
    fn unwrap_validated(self) -> T {
12
14.7k
        self.expect("Validation guarantees this to be `Some(_)`, but it is `None`")
13
14.7k
    }
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
6.45k
    fn unwrap_validated(self) -> T {
19
6.45k
        self.unwrap_or_else(|e| {
20
0
            panic!("Validation guarantees this to be `Ok(_)`, but it is `Err({e:?})`");
21
6.45k
        })
22
6.45k
    }
23
}
24
25
#[macro_export]
26
macro_rules! unreachable_validated {
27
    () => {
28
        unreachable!("because of prior validation")
29
    };
30
}