reth::rpc::result

Trait ToRpcResult

pub trait ToRpcResult<Ok, Err>: Sized {
    // Required methods
    fn map_rpc_err<'a, F, M>(self, op: F) -> Result<Ok, ErrorObject<'static>>
       where F: FnOnce(Err) -> (i32, M, Option<&'a [u8]>),
             M: Into<String>;
    fn map_internal_err<F, M>(self, op: F) -> Result<Ok, ErrorObject<'static>>
       where F: FnOnce(Err) -> M,
             M: Into<String>;
    fn map_internal_err_with_data<'a, F, M>(
        self,
        op: F,
    ) -> Result<Ok, ErrorObject<'static>>
       where F: FnOnce(Err) -> (M, &'a [u8]),
             M: Into<String>;
    fn with_message(self, msg: &str) -> Result<Ok, ErrorObject<'static>>;

    // Provided method
    fn to_rpc_result(self) -> Result<Ok, ErrorObject<'static>>
       where Err: Display { ... }
}
Expand description

Helper trait to easily convert various Result types into [RpcResult]

Required Methods§

fn map_rpc_err<'a, F, M>(self, op: F) -> Result<Ok, ErrorObject<'static>>
where F: FnOnce(Err) -> (i32, M, Option<&'a [u8]>), M: Into<String>,

Converts this type into an [RpcResult]

fn map_internal_err<F, M>(self, op: F) -> Result<Ok, ErrorObject<'static>>
where F: FnOnce(Err) -> M, M: Into<String>,

Converts this type into an [RpcResult] with the [jsonrpsee_types::error::INTERNAL_ERROR_CODE] and the given message.

fn map_internal_err_with_data<'a, F, M>( self, op: F, ) -> Result<Ok, ErrorObject<'static>>
where F: FnOnce(Err) -> (M, &'a [u8]), M: Into<String>,

Converts this type into an [RpcResult] with the [jsonrpsee_types::error::INTERNAL_ERROR_CODE] and given message and data.

fn with_message(self, msg: &str) -> Result<Ok, ErrorObject<'static>>

Adds a message to the error variant and returns an internal Error.

This is shorthand for Self::map_internal_err(|err| format!("{msg}: {err}")).

Provided Methods§

fn to_rpc_result(self) -> Result<Ok, ErrorObject<'static>>
where Err: Display,

Converts result to [RpcResult] by converting error variant to [jsonrpsee_types::error::ErrorObject]

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§

§

impl<Ok> ToRpcResult<Ok, ProviderError> for Result<Ok, ProviderError>

§

fn map_rpc_err<'a, F, M>(self, op: F) -> Result<Ok, ErrorObject<'static>>
where F: FnOnce(ProviderError) -> (i32, M, Option<&'a [u8]>), M: Into<String>,

§

fn map_internal_err<'a, F, M>(self, op: F) -> Result<Ok, ErrorObject<'static>>
where F: FnOnce(ProviderError) -> M, M: Into<String>,

§

fn map_internal_err_with_data<'a, F, M>( self, op: F, ) -> Result<Ok, ErrorObject<'static>>
where F: FnOnce(ProviderError) -> (M, &'a [u8]), M: Into<String>,

§

fn with_message(self, msg: &str) -> Result<Ok, ErrorObject<'static>>

§

impl<Ok> ToRpcResult<Ok, ConsensusError> for Result<Ok, ConsensusError>

§

fn map_rpc_err<'a, F, M>(self, op: F) -> Result<Ok, ErrorObject<'static>>
where F: FnOnce(ConsensusError) -> (i32, M, Option<&'a [u8]>), M: Into<String>,

§

fn map_internal_err<'a, F, M>(self, op: F) -> Result<Ok, ErrorObject<'static>>
where F: FnOnce(ConsensusError) -> M, M: Into<String>,

§

fn map_internal_err_with_data<'a, F, M>( self, op: F, ) -> Result<Ok, ErrorObject<'static>>
where F: FnOnce(ConsensusError) -> (M, &'a [u8]), M: Into<String>,

§

fn with_message(self, msg: &str) -> Result<Ok, ErrorObject<'static>>

§

impl<Ok> ToRpcResult<Ok, PayloadError> for Result<Ok, PayloadError>

§

fn map_rpc_err<'a, F, M>(self, op: F) -> Result<Ok, ErrorObject<'static>>
where F: FnOnce(PayloadError) -> (i32, M, Option<&'a [u8]>), M: Into<String>,

§

fn map_internal_err<'a, F, M>(self, op: F) -> Result<Ok, ErrorObject<'static>>
where F: FnOnce(PayloadError) -> M, M: Into<String>,

§

fn map_internal_err_with_data<'a, F, M>( self, op: F, ) -> Result<Ok, ErrorObject<'static>>
where F: FnOnce(PayloadError) -> (M, &'a [u8]), M: Into<String>,

§

fn with_message(self, msg: &str) -> Result<Ok, ErrorObject<'static>>

§

impl<Ok> ToRpcResult<Ok, NetworkError> for Result<Ok, NetworkError>

§

fn map_rpc_err<'a, F, M>(self, op: F) -> Result<Ok, ErrorObject<'static>>
where F: FnOnce(NetworkError) -> (i32, M, Option<&'a [u8]>), M: Into<String>,

§

fn map_internal_err<'a, F, M>(self, op: F) -> Result<Ok, ErrorObject<'static>>
where F: FnOnce(NetworkError) -> M, M: Into<String>,

§

fn map_internal_err_with_data<'a, F, M>( self, op: F, ) -> Result<Ok, ErrorObject<'static>>
where F: FnOnce(NetworkError) -> (M, &'a [u8]), M: Into<String>,

§

fn with_message(self, msg: &str) -> Result<Ok, ErrorObject<'static>>

§

impl<Ok> ToRpcResult<Ok, RethError> for Result<Ok, RethError>

§

fn map_rpc_err<'a, F, M>(self, op: F) -> Result<Ok, ErrorObject<'static>>
where F: FnOnce(RethError) -> (i32, M, Option<&'a [u8]>), M: Into<String>,

§

fn map_internal_err<'a, F, M>(self, op: F) -> Result<Ok, ErrorObject<'static>>
where F: FnOnce(RethError) -> M, M: Into<String>,

§

fn map_internal_err_with_data<'a, F, M>( self, op: F, ) -> Result<Ok, ErrorObject<'static>>
where F: FnOnce(RethError) -> (M, &'a [u8]), M: Into<String>,

§

fn with_message(self, msg: &str) -> Result<Ok, ErrorObject<'static>>

Implementors§