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>>
fn map_rpc_err<'a, F, M>(self, op: F) -> Result<Ok, ErrorObject<'static>>
Converts this type into an [RpcResult
]
fn map_internal_err<F, M>(self, op: F) -> Result<Ok, ErrorObject<'static>>
fn map_internal_err<F, M>(self, op: F) -> Result<Ok, ErrorObject<'static>>
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>>
fn map_internal_err_with_data<'a, F, M>( self, op: F, ) -> Result<Ok, ErrorObject<'static>>
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>>
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,
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.