#[cfg(feature = "tracing")]
use std::fmt::{self, Display};
use bytes::BytesMut;
use enum_dispatch::enum_dispatch;
use super::actions::{
Abort, Action, Continue, Discard, Quit, QuitNc, Reject, Replycode, Skip, Tempfail,
};
use super::modifications::ModificationAction;
use super::commands::{
Body, Command, Connect, Data, EndOfBody, EndOfHeader, Header, Helo, Mail, Recipient, Unknown,
};
use super::optneg::OptNeg;
#[enum_dispatch(ServerMessage)]
#[enum_dispatch(ClientMessage)]
#[enum_dispatch(ModificationAction)]
#[enum_dispatch(Command)]
#[enum_dispatch(Action)]
#[enum_dispatch(OptNeg)]
pub trait Writable {
fn write(&self, buffer: &mut BytesMut);
fn len(&self) -> usize;
fn code(&self) -> u8;
fn is_empty(&self) -> bool;
}
#[enum_dispatch]
#[derive(Debug)]
pub enum ServerMessage {
Optneg(OptNeg),
Action,
ModificationAction,
}
#[cfg(feature = "tracing")]
impl Display for ServerMessage {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
ServerMessage::Optneg(_optneg) => write!(f, "Optneg"),
ServerMessage::Action(action) => write!(f, "Action/{action}"),
ServerMessage::ModificationAction(mod_action) => {
write!(f, "ModificationAction/{mod_action}")
}
}
}
}
#[enum_dispatch]
#[derive(Debug)]
pub enum ClientMessage {
Optneg(OptNeg),
Action,
Command,
}
#[cfg(feature = "tracing")]
impl Display for ClientMessage {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
ClientMessage::Optneg(_optneg) => write!(f, "Optneg"),
ClientMessage::Action(action) => write!(f, "Action/{action}"),
ClientMessage::Command(command) => write!(f, "Command/{command}"),
}
}
}