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