wasm/execution/
assert_validated.rs

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