pub trait ToRpcResult<Ok, Err>: Sized {
// Required methods
fn map_rpc_err<'a, F, M>(self, op: F) -> RpcResult<Ok>
where F: FnOnce(Err) -> (i32, M, Option<&'a [u8]>),
M: Into<String>;
fn map_internal_err<F, M>(self, op: F) -> RpcResult<Ok>
where F: FnOnce(Err) -> M,
M: Into<String>;
fn map_internal_err_with_data<'a, F, M>(self, op: F) -> RpcResult<Ok>
where F: FnOnce(Err) -> (M, &'a [u8]),
M: Into<String>;
fn with_message(self, msg: &str) -> RpcResult<Ok>;
// Provided method
fn to_rpc_result(self) -> RpcResult<Ok>
where Err: Display { ... }
}
Expand description
Helper trait to easily convert various Result
types into [RpcResult
]
Required Methods§
Sourcefn map_rpc_err<'a, F, M>(self, op: F) -> RpcResult<Ok>
fn map_rpc_err<'a, F, M>(self, op: F) -> RpcResult<Ok>
Converts this type into an [RpcResult
]
Sourcefn map_internal_err<F, M>(self, op: F) -> RpcResult<Ok>
fn map_internal_err<F, M>(self, op: F) -> RpcResult<Ok>
Converts this type into an [RpcResult
] with the
[jsonrpsee_types::error::INTERNAL_ERROR_CODE
] and the given message.
Sourcefn map_internal_err_with_data<'a, F, M>(self, op: F) -> RpcResult<Ok>
fn map_internal_err_with_data<'a, F, M>(self, op: F) -> RpcResult<Ok>
Converts this type into an [RpcResult
] with the
[jsonrpsee_types::error::INTERNAL_ERROR_CODE
] and given message and data.
Sourcefn with_message(self, msg: &str) -> RpcResult<Ok>
fn with_message(self, msg: &str) -> RpcResult<Ok>
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§
Sourcefn to_rpc_result(self) -> RpcResult<Ok>where
Err: Display,
fn to_rpc_result(self) -> RpcResult<Ok>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.