pub trait CapnpResultExt<T> {
// Required methods
fn rpc_err(self) -> Result<T, RpcError>;
fn transport_err(self) -> Result<T, RpcError>;
}Expand description
Extension trait for adding RPC error context to Results.
Simplifies the common pattern of mapping errors to RPC errors.
§Example
ⓘ
use hyprstream_rpc::capnp::CapnpResultExt;
// Instead of:
let value = reader.get_field()
.map_err(|e| RpcError::serialization(e.to_string()))?
.to_str()
.map_err(|e| RpcError::serialization(e.to_string()))?;
// Write:
let value = reader.get_field().rpc_err()?.to_str().rpc_err()?;Required Methods§
Sourcefn transport_err(self) -> Result<T, RpcError>
fn transport_err(self) -> Result<T, RpcError>
Convert error to RpcError::Transport.