mirror of
https://github.com/hinto-janai/cuprate.git
synced 2025-02-01 07:15:56 +00:00
add Status::Other(String)
This commit is contained in:
parent
d72c96ab9c
commit
87e99da0eb
2 changed files with 16 additions and 9 deletions
|
@ -35,7 +35,7 @@ define_request_and_response! {
|
||||||
//
|
//
|
||||||
// If there are any additional attributes (`/// docs` or `#[derive]`s)
|
// If there are any additional attributes (`/// docs` or `#[derive]`s)
|
||||||
// for the struct, they go here, e.g.:
|
// for the struct, they go here, e.g.:
|
||||||
#[derive(Copy)]
|
// #[derive(Copy)]
|
||||||
Response {
|
Response {
|
||||||
// Within the `{}` is an infinite matching pattern of:
|
// Within the `{}` is an infinite matching pattern of:
|
||||||
// ```
|
// ```
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use strum::{
|
use strum::{
|
||||||
AsRefStr, Display, EnumCount, EnumIs, EnumIter, EnumMessage, EnumProperty, EnumString,
|
AsRefStr, Display, EnumCount, EnumIs, EnumIter, EnumMessage, EnumProperty, EnumString,
|
||||||
EnumTryAs, FromRepr, IntoStaticStr, VariantArray, VariantNames,
|
FromRepr, IntoStaticStr, VariantNames,
|
||||||
};
|
};
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------- TODO
|
//---------------------------------------------------------------------------------------------------- TODO
|
||||||
|
@ -22,38 +22,44 @@ use strum::{
|
||||||
/// use serde_json::to_string;
|
/// use serde_json::to_string;
|
||||||
/// use strum::AsRefStr;
|
/// use strum::AsRefStr;
|
||||||
///
|
///
|
||||||
|
/// let other = Status::Other("hello".into());
|
||||||
|
///
|
||||||
/// assert_eq!(to_string(&Status::Ok).unwrap(), r#""OK""#);
|
/// assert_eq!(to_string(&Status::Ok).unwrap(), r#""OK""#);
|
||||||
/// assert_eq!(to_string(&Status::Retry).unwrap(), r#""Retry""#);
|
/// assert_eq!(to_string(&Status::Retry).unwrap(), r#""Retry""#);
|
||||||
/// assert_eq!(to_string(&Status::Failed).unwrap(), r#""Failed""#);
|
/// assert_eq!(to_string(&Status::Failed).unwrap(), r#""Failed""#);
|
||||||
/// assert_eq!(to_string(&Status::BadRequest).unwrap(), r#""Invalid request type""#);
|
/// assert_eq!(to_string(&Status::BadRequest).unwrap(), r#""Invalid request type""#);
|
||||||
/// assert_eq!(to_string(&Status::BadJson).unwrap(), r#""Malformed json""#);
|
/// assert_eq!(to_string(&Status::BadJson).unwrap(), r#""Malformed json""#);
|
||||||
|
/// assert_eq!(to_string(&other).unwrap(), r#""hello""#);
|
||||||
///
|
///
|
||||||
/// assert_eq!(Status::Ok.as_ref(), "OK");
|
/// assert_eq!(Status::Ok.as_ref(), "OK");
|
||||||
/// assert_eq!(Status::Retry.as_ref(), "Retry");
|
/// assert_eq!(Status::Retry.as_ref(), "Retry");
|
||||||
/// assert_eq!(Status::Failed.as_ref(), "Failed");
|
/// assert_eq!(Status::Failed.as_ref(), "Failed");
|
||||||
/// assert_eq!(Status::BadRequest.as_ref(), "Invalid request type");
|
/// assert_eq!(Status::BadRequest.as_ref(), "Invalid request type");
|
||||||
/// assert_eq!(Status::BadJson.as_ref(), "Malformed json");
|
/// assert_eq!(Status::BadJson.as_ref(), "Malformed json");
|
||||||
|
/// assert_eq!(other.as_ref(), "Other");
|
||||||
///
|
///
|
||||||
/// assert_eq!(format!("{}", Status::Ok), "OK");
|
/// assert_eq!(format!("{}", Status::Ok), "OK");
|
||||||
/// assert_eq!(format!("{}", Status::Retry), "Retry");
|
/// assert_eq!(format!("{}", Status::Retry), "Retry");
|
||||||
/// assert_eq!(format!("{}", Status::Failed), "Failed");
|
/// assert_eq!(format!("{}", Status::Failed), "Failed");
|
||||||
/// assert_eq!(format!("{}", Status::BadRequest), "Invalid request type");
|
/// assert_eq!(format!("{}", Status::BadRequest), "Invalid request type");
|
||||||
/// assert_eq!(format!("{}", Status::BadJson), "Malformed json");
|
/// assert_eq!(format!("{}", Status::BadJson), "Malformed json");
|
||||||
|
/// assert_eq!(format!("{}", other), "Other");
|
||||||
///
|
///
|
||||||
/// assert_eq!(format!("{:?}", Status::Ok), "Ok");
|
/// assert_eq!(format!("{:?}", Status::Ok), "Ok");
|
||||||
/// assert_eq!(format!("{:?}", Status::Retry), "Retry");
|
/// assert_eq!(format!("{:?}", Status::Retry), "Retry");
|
||||||
/// assert_eq!(format!("{:?}", Status::Failed), "Failed");
|
/// assert_eq!(format!("{:?}", Status::Failed), "Failed");
|
||||||
/// assert_eq!(format!("{:?}", Status::BadRequest), "BadRequest");
|
/// assert_eq!(format!("{:?}", Status::BadRequest), "BadRequest");
|
||||||
/// assert_eq!(format!("{:?}", Status::BadJson), "BadJson");
|
/// assert_eq!(format!("{:?}", Status::BadJson), "BadJson");
|
||||||
|
/// assert_eq!(format!("{:?}", other), "Other(\"hello\")");
|
||||||
///
|
///
|
||||||
/// assert_eq!(format!("{:#?}", Status::Ok), "Ok");
|
/// assert_eq!(format!("{:#?}", Status::Ok), "Ok");
|
||||||
/// assert_eq!(format!("{:#?}", Status::Retry), "Retry");
|
/// assert_eq!(format!("{:#?}", Status::Retry), "Retry");
|
||||||
/// assert_eq!(format!("{:#?}", Status::Failed), "Failed");
|
/// assert_eq!(format!("{:#?}", Status::Failed), "Failed");
|
||||||
/// assert_eq!(format!("{:#?}", Status::BadRequest), "BadRequest");
|
/// assert_eq!(format!("{:#?}", Status::BadRequest), "BadRequest");
|
||||||
/// assert_eq!(format!("{:#?}", Status::BadJson), "BadJson");
|
/// assert_eq!(format!("{:#?}", Status::BadJson), "BadJson");
|
||||||
|
/// assert_eq!(format!("{:#?}", other), "Other(\n \"hello\",\n)");
|
||||||
/// ```
|
/// ```
|
||||||
#[derive(
|
#[derive(
|
||||||
Copy,
|
|
||||||
Clone,
|
Clone,
|
||||||
Debug,
|
Debug,
|
||||||
Default,
|
Default,
|
||||||
|
@ -70,10 +76,8 @@ use strum::{
|
||||||
EnumMessage,
|
EnumMessage,
|
||||||
EnumProperty,
|
EnumProperty,
|
||||||
EnumString,
|
EnumString,
|
||||||
EnumTryAs,
|
|
||||||
FromRepr,
|
FromRepr,
|
||||||
IntoStaticStr,
|
IntoStaticStr,
|
||||||
VariantArray,
|
|
||||||
VariantNames,
|
VariantNames,
|
||||||
Serialize,
|
Serialize,
|
||||||
Deserialize,
|
Deserialize,
|
||||||
|
@ -114,10 +118,13 @@ pub enum Status {
|
||||||
alias = "malformed JSON"
|
alias = "malformed JSON"
|
||||||
)]
|
)]
|
||||||
BadJson,
|
BadJson,
|
||||||
// TODO:
|
|
||||||
// This may not be all the string `monerod` uses.
|
#[serde(untagged)]
|
||||||
// We could use an `Other(String)` here just in case,
|
/// Some unknown other string.
|
||||||
// otherwise deserialization would fail.
|
///
|
||||||
|
/// This exists to act as a catch-all if `monerod` adds
|
||||||
|
/// a string and a Cuprate node hasn't updated yet.
|
||||||
|
Other(String),
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------- Tests
|
//---------------------------------------------------------------------------------------------------- Tests
|
||||||
|
|
Loading…
Reference in a new issue