reth::rpc::server_types

Trait ToRpcResult

Source
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§

Source

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]

Source

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.

Source

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.

Source

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§

Source

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§

Source§

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

Source§

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>,

Source§

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

Source§

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>,

Source§

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

Source§

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

Source§

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>,

Source§

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

Source§

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>,

Source§

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

Source§

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

Source§

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>,

Source§

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

Source§

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>,

Source§

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

Source§

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

Source§

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>,

Source§

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

Source§

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>,

Source§

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

Source§

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

Source§

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>,

Source§

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

Source§

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>,

Source§

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

Implementors§