mirror of
https://github.com/hinto-janai/cuprate.git
synced 2025-02-03 19:56:35 +00:00
fix/doc type serde
This commit is contained in:
parent
82583263fe
commit
604ecc8393
3 changed files with 51 additions and 10 deletions
|
@ -658,7 +658,7 @@ define_request_and_response! {
|
||||||
connections: vec![
|
connections: vec![
|
||||||
ConnectionInfo {
|
ConnectionInfo {
|
||||||
address: "3evk3kezfjg44ma6tvesy7rbxwwpgpympj45xar5fo4qajrsmkoaqdqd.onion:18083".into(),
|
address: "3evk3kezfjg44ma6tvesy7rbxwwpgpympj45xar5fo4qajrsmkoaqdqd.onion:18083".into(),
|
||||||
address_type: cuprate_rpc_types::misc::AddressType::Tor,
|
address_type: cuprate_types::AddressType::Tor,
|
||||||
avg_download: 0,
|
avg_download: 0,
|
||||||
avg_upload: 0,
|
avg_upload: 0,
|
||||||
connection_id: "22ef856d0f1d44cc95e84fecfd065fe2".into(),
|
connection_id: "22ef856d0f1d44cc95e84fecfd065fe2".into(),
|
||||||
|
@ -680,12 +680,12 @@ define_request_and_response! {
|
||||||
rpc_port: 0,
|
rpc_port: 0,
|
||||||
send_count: 3406572,
|
send_count: 3406572,
|
||||||
send_idle_time: 30,
|
send_idle_time: 30,
|
||||||
state: "normal".into(),
|
state: cuprate_types::ConnectionState::Normal,
|
||||||
support_flags: 0
|
support_flags: 0
|
||||||
},
|
},
|
||||||
ConnectionInfo {
|
ConnectionInfo {
|
||||||
address: "4iykytmumafy5kjahdqc7uzgcs34s2vwsadfjpk4znvsa5vmcxeup2qd.onion:18083".into(),
|
address: "4iykytmumafy5kjahdqc7uzgcs34s2vwsadfjpk4znvsa5vmcxeup2qd.onion:18083".into(),
|
||||||
address_type: cuprate_rpc_types::misc::AddressType::Tor,
|
address_type: cuprate_types::AddressType::Tor,
|
||||||
avg_download: 0,
|
avg_download: 0,
|
||||||
avg_upload: 0,
|
avg_upload: 0,
|
||||||
connection_id: "c7734e15936f485a86d2b0534f87e499".into(),
|
connection_id: "c7734e15936f485a86d2b0534f87e499".into(),
|
||||||
|
@ -707,7 +707,7 @@ define_request_and_response! {
|
||||||
rpc_port: 0,
|
rpc_port: 0,
|
||||||
send_count: 3370566,
|
send_count: 3370566,
|
||||||
send_idle_time: 120,
|
send_idle_time: 120,
|
||||||
state: "normal".into(),
|
state: cuprate_types::ConnectionState::Normal,
|
||||||
support_flags: 0
|
support_flags: 0
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
@ -1251,7 +1251,7 @@ define_request_and_response! {
|
||||||
SyncInfoPeer {
|
SyncInfoPeer {
|
||||||
info: ConnectionInfo {
|
info: ConnectionInfo {
|
||||||
address: "142.93.128.65:44986".into(),
|
address: "142.93.128.65:44986".into(),
|
||||||
address_type: AddressType::Ipv4,
|
address_type: cuprate_types::AddressType::Ipv4,
|
||||||
avg_download: 1,
|
avg_download: 1,
|
||||||
avg_upload: 1,
|
avg_upload: 1,
|
||||||
connection_id: "a5803c4c2dac49e7b201dccdef54c862".into(),
|
connection_id: "a5803c4c2dac49e7b201dccdef54c862".into(),
|
||||||
|
@ -1273,14 +1273,14 @@ define_request_and_response! {
|
||||||
rpc_port: 18089,
|
rpc_port: 18089,
|
||||||
send_count: 32235,
|
send_count: 32235,
|
||||||
send_idle_time: 6,
|
send_idle_time: 6,
|
||||||
state: "normal".into(),
|
state: cuprate_types::ConnectionState::Normal,
|
||||||
support_flags: 1
|
support_flags: 1
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
SyncInfoPeer {
|
SyncInfoPeer {
|
||||||
info: ConnectionInfo {
|
info: ConnectionInfo {
|
||||||
address: "4iykytmumafy5kjahdqc7uzgcs34s2vwsadfjpk4znvsa5vmcxeup2qd.onion:18083".into(),
|
address: "4iykytmumafy5kjahdqc7uzgcs34s2vwsadfjpk4znvsa5vmcxeup2qd.onion:18083".into(),
|
||||||
address_type: AddressType::Tor,
|
address_type: cuprate_types::AddressType::Tor,
|
||||||
avg_download: 0,
|
avg_download: 0,
|
||||||
avg_upload: 0,
|
avg_upload: 0,
|
||||||
connection_id: "277f7c821bc546878c8bd29977e780f5".into(),
|
connection_id: "277f7c821bc546878c8bd29977e780f5".into(),
|
||||||
|
@ -1302,7 +1302,7 @@ define_request_and_response! {
|
||||||
rpc_port: 0,
|
rpc_port: 0,
|
||||||
send_count: 99120,
|
send_count: 99120,
|
||||||
send_idle_time: 15,
|
send_idle_time: 15,
|
||||||
state: "normal".into(),
|
state: cuprate_types::ConnectionState::Normal,
|
||||||
support_flags: 0
|
support_flags: 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,6 +20,26 @@ use strum::{
|
||||||
///
|
///
|
||||||
/// Original definition:
|
/// Original definition:
|
||||||
/// - <https://github.com/monero-project/monero/blob/cc73fe71162d564ffda8e549b79a350bca53c454/src/epee/include/net/enums.h/#L49>
|
/// - <https://github.com/monero-project/monero/blob/cc73fe71162d564ffda8e549b79a350bca53c454/src/epee/include/net/enums.h/#L49>
|
||||||
|
///
|
||||||
|
/// # Serde
|
||||||
|
/// This type's `serde` implementation (de)serializes from a [`u8`].
|
||||||
|
///
|
||||||
|
/// ```rust
|
||||||
|
/// use cuprate_types::AddressType as A;
|
||||||
|
/// use serde_json::{to_string, from_str};
|
||||||
|
///
|
||||||
|
/// assert_eq!(from_str::<A>(&"0").unwrap(), A::Invalid);
|
||||||
|
/// assert_eq!(from_str::<A>(&"1").unwrap(), A::Ipv4);
|
||||||
|
/// assert_eq!(from_str::<A>(&"2").unwrap(), A::Ipv6);
|
||||||
|
/// assert_eq!(from_str::<A>(&"3").unwrap(), A::I2p);
|
||||||
|
/// assert_eq!(from_str::<A>(&"4").unwrap(), A::Tor);
|
||||||
|
///
|
||||||
|
/// assert_eq!(to_string(&A::Invalid).unwrap(), "0");
|
||||||
|
/// assert_eq!(to_string(&A::Ipv4).unwrap(), "1");
|
||||||
|
/// assert_eq!(to_string(&A::Ipv6).unwrap(), "2");
|
||||||
|
/// assert_eq!(to_string(&A::I2p).unwrap(), "3");
|
||||||
|
/// assert_eq!(to_string(&A::Tor).unwrap(), "4");
|
||||||
|
/// ```
|
||||||
#[derive(
|
#[derive(
|
||||||
Copy,
|
Copy,
|
||||||
Clone,
|
Clone,
|
||||||
|
|
|
@ -20,6 +20,26 @@ use strum::{
|
||||||
///
|
///
|
||||||
/// Original definition:
|
/// Original definition:
|
||||||
/// - <https://github.com/monero-project/monero/blob/893916ad091a92e765ce3241b94e706ad012b62a/src/cryptonote_basic/connection_context.h#L49>
|
/// - <https://github.com/monero-project/monero/blob/893916ad091a92e765ce3241b94e706ad012b62a/src/cryptonote_basic/connection_context.h#L49>
|
||||||
|
///
|
||||||
|
/// # Serde
|
||||||
|
/// This type's `serde` implementation depends on `snake_case`.
|
||||||
|
///
|
||||||
|
/// ```rust
|
||||||
|
/// use cuprate_types::ConnectionState as C;
|
||||||
|
/// use serde_json::to_string;
|
||||||
|
///
|
||||||
|
/// assert_eq!(to_string(&C::BeforeHandshake).unwrap(), r#""before_handshake""#);
|
||||||
|
/// assert_eq!(to_string(&C::Synchronizing).unwrap(), r#""synchronizing""#);
|
||||||
|
/// assert_eq!(to_string(&C::Standby).unwrap(), r#""standby""#);
|
||||||
|
/// assert_eq!(to_string(&C::Idle).unwrap(), r#""idle""#);
|
||||||
|
/// assert_eq!(to_string(&C::Normal).unwrap(), r#""normal""#);
|
||||||
|
///
|
||||||
|
/// assert_eq!(C::BeforeHandshake.to_string(), "before_handshake");
|
||||||
|
/// assert_eq!(C::Synchronizing.to_string(), "synchronizing");
|
||||||
|
/// assert_eq!(C::Standby.to_string(), "standby");
|
||||||
|
/// assert_eq!(C::Idle.to_string(), "idle");
|
||||||
|
/// assert_eq!(C::Normal.to_string(), "normal");
|
||||||
|
/// ```
|
||||||
#[derive(
|
#[derive(
|
||||||
Copy,
|
Copy,
|
||||||
Clone,
|
Clone,
|
||||||
|
@ -40,7 +60,8 @@ use strum::{
|
||||||
VariantArray,
|
VariantArray,
|
||||||
)]
|
)]
|
||||||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
||||||
#[cfg_attr(feature = "serde", serde(untagged, try_from = "u8", into = "u8"))]
|
#[cfg_attr(feature = "serde", serde(rename_all = "snake_case"))] // cuprate-rpc-types depends on snake_case
|
||||||
|
#[strum(serialize_all = "snake_case")]
|
||||||
#[repr(u8)]
|
#[repr(u8)]
|
||||||
pub enum ConnectionState {
|
pub enum ConnectionState {
|
||||||
BeforeHandshake,
|
BeforeHandshake,
|
||||||
|
@ -75,7 +96,7 @@ impl ConnectionState {
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// use cuprate_types::ConnectionState as C;
|
/// use cuprate_types::ConnectionState as C;
|
||||||
///
|
///
|
||||||
/// assert_eq!(C::from_u8(0), Some(C::BeforeHandShake));
|
/// assert_eq!(C::from_u8(0), Some(C::BeforeHandshake));
|
||||||
/// assert_eq!(C::from_u8(1), Some(C::Synchronizing));
|
/// assert_eq!(C::from_u8(1), Some(C::Synchronizing));
|
||||||
/// assert_eq!(C::from_u8(2), Some(C::Standby));
|
/// assert_eq!(C::from_u8(2), Some(C::Standby));
|
||||||
/// assert_eq!(C::from_u8(3), Some(C::Idle));
|
/// assert_eq!(C::from_u8(3), Some(C::Idle));
|
||||||
|
|
Loading…
Reference in a new issue