pub trait ErrorCodeT:
Into<(i64, &'static str)>
+ for<'de> Deserialize<'de>
+ Copy
+ Eq
+ Debug { }
Expand description
A marker trait for a type suitable for use as an error code when constructing an Error
.
The implementing type must also implement Into<(i64, &'static str)>
where the tuple represents
the “code” and “message” fields of the Error
.
As per the JSON-RPC specification, the code must not fall in the reserved range, i.e. it must not be between -32768 and -32000 inclusive.
Generally the “message” will be a brief const &str, where additional request-specific info can
be provided via the additional_info
parameter of Error::new
.
§Example
use serde::{Deserialize, Serialize};
use casper_json_rpc::ErrorCodeT;
#[derive(Copy, Clone, Eq, PartialEq, Serialize, Deserialize, Debug)]
#[repr(i64)]
pub enum ErrorCode {
/// The requested item was not found.
NoSuchItem = -1,
/// Failed to put the requested item to storage.
FailedToPutItem = -2,
}
impl From<ErrorCode> for (i64, &'static str) {
fn from(error_code: ErrorCode) -> Self {
match error_code {
ErrorCode::NoSuchItem => (error_code as i64, "No such item"),
ErrorCode::FailedToPutItem => (error_code as i64, "Failed to put item"),
}
}
}
impl ErrorCodeT for ErrorCode {}
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.