cuprate_rpc_types/misc/
requested_info.rs
1#[cfg(feature = "serde")]
5use serde::{Deserialize, Serialize};
6
7#[cfg(feature = "epee")]
8use cuprate_epee_encoding::{
9 error,
10 macros::bytes::{Buf, BufMut},
11 EpeeValue, Marker,
12};
13
14#[doc = crate::macros::monero_definition_link!(
16 "cc73fe71162d564ffda8e549b79a350bca53c454",
17 "rpc/core_rpc_server_commands_defs.h",
18 178..=183
19)]
20#[derive(Copy, Clone, Default, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
22#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
23#[cfg_attr(feature = "serde", serde(try_from = "u8", into = "u8"))]
24#[repr(u8)]
25pub enum RequestedInfo {
26 #[default]
27 BlocksOnly = 0,
28 BlocksAndPool = 1,
29 PoolOnly = 2,
30}
31
32impl RequestedInfo {
33 pub const fn to_u8(self) -> u8 {
43 match self {
44 Self::BlocksOnly => 0,
45 Self::BlocksAndPool => 1,
46 Self::PoolOnly => 2,
47 }
48 }
49
50 pub const fn from_u8(u: u8) -> Option<Self> {
64 Some(match u {
65 0 => Self::BlocksOnly,
66 1 => Self::BlocksAndPool,
67 2 => Self::PoolOnly,
68 _ => return None,
69 })
70 }
71}
72
73impl From<RequestedInfo> for u8 {
74 fn from(value: RequestedInfo) -> Self {
75 value.to_u8()
76 }
77}
78
79impl TryFrom<u8> for RequestedInfo {
80 type Error = u8;
81 fn try_from(value: u8) -> Result<Self, Self::Error> {
82 Self::from_u8(value).ok_or(value)
83 }
84}
85
86#[cfg(feature = "epee")]
87impl EpeeValue for RequestedInfo {
88 const MARKER: Marker = u8::MARKER;
89
90 fn read<B: Buf>(r: &mut B, marker: &Marker) -> error::Result<Self> {
91 let u = u8::read(r, marker)?;
92 Self::from_u8(u).ok_or(error::Error::Format("u8 was greater than 2"))
93 }
94
95 fn write<B: BufMut>(self, w: &mut B) -> error::Result<()> {
96 let u = self.to_u8();
97 u8::write(u, w)?;
98 Ok(())
99 }
100}