use crate::{std::fmt, ChannelValue};
use super::Method;
#[derive(Clone, Copy, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize)]
pub struct StackEvent {
value: ChannelValue,
}
impl StackEvent {
pub const fn new(value: ChannelValue) -> Self {
Self { value }
}
pub const fn method() -> Method {
Method::Stack
}
pub const fn to_str(&self) -> &'static str {
Self::method().to_str()
}
pub const fn value(&self) -> ChannelValue {
self.value
}
pub const fn len() -> usize {
2
}
}
impl From<&StackEvent> for &'static str {
fn from(val: &StackEvent) -> Self {
val.to_str()
}
}
impl From<StackEvent> for &'static str {
fn from(val: StackEvent) -> Self {
(&val).into()
}
}
impl From<ChannelValue> for StackEvent {
fn from(val: ChannelValue) -> Self {
Self::new(val)
}
}
impl From<&ChannelValue> for StackEvent {
fn from(val: &ChannelValue) -> Self {
(*val).into()
}
}
impl fmt::Display for StackEvent {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let method = self.to_str();
let value = self.value();
write!(f, r#"{{"{method}": {{"value": {value}}}}}"#)
}
}