zebra_rpc::server::error

Trait OkOrError

Source
pub(crate) trait OkOrError<T>: Sized {
    // Required method
    fn ok_or_error(
        self,
        code: impl Into<ErrorCode>,
        message: impl ToString,
    ) -> Result<T, ErrorObjectOwned>;

    // Provided method
    fn ok_or_misc_error(
        self,
        message: impl ToString,
    ) -> Result<T, ErrorObjectOwned> { ... }
}
Expand description

A trait for conditionally converting a value into a Result<T, jsonrpc_core::Error>.

Required Methods§

Source

fn ok_or_error( self, code: impl Into<ErrorCode>, message: impl ToString, ) -> Result<T, ErrorObjectOwned>

Converts the implementing type to Result<T, jsonrpc_core::Error>, using an error code and message if conversion is to Err.

Provided Methods§

Source

fn ok_or_misc_error(self, message: impl ToString) -> Result<T, ErrorObjectOwned>

Converts the implementing type to Result<T, jsonrpc_core::Error>, using a LegacyCode::Misc error code.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl<T> OkOrError<T> for Option<T>

Source§

fn ok_or_error( self, code: impl Into<ErrorCode>, message: impl ToString, ) -> Result<T, ErrorObjectOwned>

Implementors§