ark_api_ffi/entrypoints/state_persist.rs
1//! State Persist capability entrypoints
2
3/// `ark_state_persist` - Persist out module state
4///
5/// If the function is successful then it will return a memory buffer through the Ark return slice mechanism, and return `ErrorCode::Success`.
6///
7/// # Example
8///
9/// ```ignore
10/// #[no_mangle]
11/// pub fn ark_state_persist() -> ErrorCode {
12/// match your_save_module_state() {
13/// Ok(state) => {
14/// ark::core::return_slice(&state);
15/// ErrorCode::Success
16/// }
17/// Err(_) => ErrorCode::InternalError,
18/// }
19/// }
20pub type StatePersistFn = fn() -> crate::ErrorCode;
21
22/// `ark_state_restore` - Restore module state
23///
24/// The parameter is a previously persisted state, accessible a `u8` memory slice with that is stored in the Wasm module's memory.
25///
26/// # Example
27///
28/// ```ignore
29/// pub fn ark_state_load(state_ptr: *const u8, state_size: u32) -> ErrorCode {
30/// let state = std::slice::from_raw_parts(state_ptr, state_size as usize);
31/// match your_load_module_state(state) {
32/// Ok(_) => ErrorCode::Success,
33/// Err(_) => ErrorCode::InternalError,
34/// }
35/// }
36/// ```
37pub type StateRestoreFn = fn(state_ptr: u32, state_size: u32) -> crate::ErrorCode;
38
39pub const STATE_PERSIST: &str = "ark_state_persist";
40pub const STATE_RESTORE: &str = "ark_state_restore";