ixc_core/
resource.rs

1//! Resource module.
2
3/// An account or module handler's resources.
4/// This is usually derived by the state management framework.
5pub unsafe trait Resources: Sized {
6    /// Initializes the resources.
7    unsafe fn new(scope: &ResourceScope) -> Result<Self, InitializationError>;
8}
9
10/// The resource scope.
11#[derive(Default)]
12pub struct ResourceScope<'a> {
13    /// The prefix of all state objects under this scope.
14    pub state_scope: &'a [u8],
15}
16
17/// A resource is anything that an account or module can use to store its own
18/// state or interact with other accounts and modules.
19pub unsafe trait StateObjectResource: Sized {
20    /// Creates a new resource.
21    /// This should only be called in generated code.
22    /// Do not call this function directly.
23    unsafe fn new(scope: &[u8], prefix: u8) -> Result<Self, InitializationError>;
24}
25
26/// An error that occurs during resource initialization.
27#[derive(Debug)]
28pub enum InitializationError {
29    /// An non-specific error occurred.
30    Other,
31}