ssp/types/events/
stacker_full.rs1use crate::{impl_default, std::fmt, Error, ResponseStatus, Result};
2
3use super::Method;
4
5#[derive(Clone, Copy, Debug, PartialEq, serde::Serialize, serde::Deserialize)]
7pub struct StackerFullEvent;
8
9impl StackerFullEvent {
10 pub const fn new() -> Self {
12 Self {}
13 }
14
15 pub const fn method() -> Method {
17 Method::StackerFull
18 }
19
20 pub const fn to_str(&self) -> &'static str {
22 Self::method().to_str()
23 }
24
25 pub const fn len() -> usize {
27 1
28 }
29}
30
31impl TryFrom<&[u8]> for StackerFullEvent {
32 type Error = Error;
33
34 fn try_from(val: &[u8]) -> Result<Self> {
35 if val.is_empty() {
36 Err(Error::InvalidLength((val.len(), 1)))
37 } else {
38 match ResponseStatus::from(val[0]) {
39 ResponseStatus::StackerFull => Ok(Self::new()),
40 event => Err(Error::InvalidEvent((event, ResponseStatus::StackerFull))),
41 }
42 }
43 }
44}
45
46impl<const N: usize> TryFrom<[u8; N]> for StackerFullEvent {
47 type Error = Error;
48
49 fn try_from(val: [u8; N]) -> Result<Self> {
50 val.as_ref().try_into()
51 }
52}
53
54impl<const N: usize> TryFrom<&[u8; N]> for StackerFullEvent {
55 type Error = Error;
56
57 fn try_from(val: &[u8; N]) -> Result<Self> {
58 val.as_ref().try_into()
59 }
60}
61
62impl From<&StackerFullEvent> for &'static str {
63 fn from(val: &StackerFullEvent) -> Self {
64 val.to_str()
65 }
66}
67
68impl From<StackerFullEvent> for &'static str {
69 fn from(val: StackerFullEvent) -> Self {
70 (&val).into()
71 }
72}
73
74impl fmt::Display for StackerFullEvent {
75 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
76 write!(f, r#"{{"{}"}}"#, self.to_str())
77 }
78}
79
80impl_default!(StackerFullEvent);