ark-api-ffi 0.17.0-pre.15

Ark low-level Wasm FFI API
Documentation
/// Error return codes for API functions.
///
/// Note that there is an [`ErrorCode::Success`],
/// so the presence of [`ErrorCode`] does NOT signify an error.
///
/// Do NOT use this type in the public interface of `ark-api`. Use idiomatic Rust error enum or [`ark_api::Error`](https://ark.embark.dev/api/ark_api/enum.Error.html) instead
#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)]
#[non_exhaustive]
#[must_use]
#[repr(u32)]
pub enum ErrorCode {
    /// Success - there was no error and the operation completed successfully
    Success = 0,

    /// API not available.
    ///
    /// Typically happens if a module calls an API it has not specified that it requires
    ApiNotAvailable = 2,

    /// Internal error - something went wrong on in the Ark host.
    ///
    /// Such an error will cause a trap on the host, causing an unload of the module triggering it.
    InternalError = 4,

    /// Invalid arguments - the inputs to the called API function were not valid
    InvalidArguments = 5,

    /// Resource not found - used by APIs to indicate a requested resource can't be found
    NotFound = 6,

    /// The API or resource is currently not available
    Unavailable = 7,

    /// HTTP request failed due to external server error - something went wrong when communicating with the remote server
    ///
    /// This can happen when sending a HTTP request to a server that is unavailable, if DNS lookup fails, or other server related issues.
    HttpRequestFailed = 8,
}

/// A result from an FFI function.
///
/// Because FFI functions cannot return multiple values, the actual type
/// returned from an FFI function will be just the error code. The actual value
/// that would be returned if the function was successful will be pulled from an
/// output argument that was passed to the extern function
pub type FFIResult<T> = Result<T, ErrorCode>;