dharitri_vm_executor/new_traits/
vm_hooks_early_exit.rs

1use std::{borrow::Cow, fmt};
2
3/// Contains details regarding an early exit triggered by a VM hook.
4///
5/// It doesn't have to be an error, for instance in the case of legacy async calls
6/// execution is intentionally halted early.
7#[derive(Debug, Clone)]
8pub struct VMHooksEarlyExit {
9    pub code: u64,
10    pub message: Cow<'static, str>,
11}
12
13impl VMHooksEarlyExit {
14    pub fn new(code: u64) -> Self {
15        VMHooksEarlyExit {
16            code,
17            message: Cow::Borrowed(""),
18        }
19    }
20
21    pub fn with_const_message(mut self, message: &'static str) -> Self {
22        self.message = Cow::Borrowed(message);
23        self
24    }
25
26    pub fn with_message(mut self, message: String) -> Self {
27        self.message = Cow::Owned(message);
28        self
29    }
30}
31
32impl fmt::Display for VMHooksEarlyExit {
33    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
34        f.debug_struct("VMHooksEarlyExit")
35            .field("code", &self.code)
36            .field("message", &self.message)
37            .finish()
38    }
39}
40
41impl std::error::Error for VMHooksEarlyExit {}