use std::fmt;
use crate::types::prelude::{ArticleNumber, NntpCommand};
#[derive(Clone, Debug)]
pub enum Article {
MessageId(String),
Number(ArticleNumber),
Current,
}
impl fmt::Display for Article {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Article::MessageId(id) => write!(f, "ARTICLE {}", id),
Article::Number(num) => write!(f, "ARTICLE {}", num),
Article::Current => write!(f, "ARTICLE"),
}
}
}
impl NntpCommand for Article {}
#[derive(Clone, Debug)]
pub enum Body {
MessageId(String),
Number(ArticleNumber),
Current,
}
impl fmt::Display for Body {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Body::MessageId(id) => write!(f, "BODY {}", id),
Body::Number(num) => write!(f, "BODY {}", num),
Body::Current => write!(f, "BODY"),
}
}
}
impl NntpCommand for Body {}
#[derive(Clone, Copy, Debug)]
pub struct Capabilities;
impl fmt::Display for Capabilities {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "CAPABILITIES")
}
}
impl NntpCommand for Capabilities {}
#[derive(Clone, Copy, Debug)]
struct Date;
impl fmt::Display for Date {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "DATE")
}
}
impl NntpCommand for Date {}
#[derive(Clone, Debug)]
pub struct Group(pub String);
impl fmt::Display for Group {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "GROUP {}", self.0)
}
}
impl NntpCommand for Group {}
#[derive(Clone, Debug)]
pub enum Hdr {
MessageId {
field: String,
id: String,
},
Range {
field: String,
low: ArticleNumber,
high: ArticleNumber,
},
Current {
field: String,
},
}
impl fmt::Display for Hdr {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Hdr::MessageId { field, id } => write!(f, "HDR {} {}", field, id),
Hdr::Range { field, low, high } => write!(f, "HDR {} {}-{}", field, low, high),
Hdr::Current { field } => write!(f, "HDR {}", field),
}
}
}
impl NntpCommand for Hdr {}
#[derive(Clone, Debug)]
pub enum Head {
MessageId(String),
Number(ArticleNumber),
Current,
}
impl fmt::Display for Head {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Head::MessageId(id) => write!(f, "HEAD {}", id),
Head::Number(num) => write!(f, "HEAD {}", num),
Head::Current => write!(f, "HEAD"),
}
}
}
impl NntpCommand for Head {}
struct Help;
impl fmt::Display for Help {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "HELP")
}
}
impl NntpCommand for Help {}
struct IHave(String);
impl fmt::Display for IHave {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "IHAVE {}", self.0)
}
}
impl NntpCommand for IHave {}
struct Last;
impl fmt::Display for Last {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "LAST")
}
}
impl NntpCommand for Last {}
#[derive(Clone, Debug)]
#[allow(missing_docs)]
pub enum List {
Active { wildmat: Option<String> },
ActiveTimes { wildmat: Option<String> },
Newsgroups { wildmat: Option<String> },
DistribPats,
OverviewFmt,
}
impl fmt::Display for List {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
fn print_wildmat(f: &mut fmt::Formatter<'_>, wildmat: Option<&String>) -> fmt::Result {
if let Some(w) = wildmat.as_ref() {
write!(f, " {}", w)
} else {
Ok(())
}
}
write!(f, "LIST")?;
match self {
List::Active { wildmat } => {
write!(f, " ACTIVE")?;
print_wildmat(f, wildmat.as_ref())
}
List::OverviewFmt => write!(f, " OVERVIEW.FMT"),
List::ActiveTimes { wildmat } => {
write!(f, " ACTIVE TIMES")?;
print_wildmat(f, wildmat.as_ref())
}
List::Newsgroups { wildmat } => {
write!(f, " ACTIVE TIMES")?;
print_wildmat(f, wildmat.as_ref())
}
List::DistribPats => write!(f, " DISTRIB.PATS"),
}
}
}
impl NntpCommand for List {}
#[derive(Clone, Copy, Debug)]
pub struct ModeReader;
impl fmt::Display for ModeReader {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "MODE READER")
}
}
impl NntpCommand for ModeReader {}
#[derive(Clone, Copy, Debug)]
pub struct Next;
impl fmt::Display for Next {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "NEXT")
}
}
impl NntpCommand for Next {}
#[derive(Clone, Debug)]
pub enum Over {
MessageId(String),
Range {
low: ArticleNumber,
high: ArticleNumber,
},
Current,
}
impl fmt::Display for Over {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Over::MessageId(id) => write!(f, "OVER {}", id),
Over::Range { low, high } => write!(f, "OVER {}-{}", low, high),
Over::Current => write!(f, "OVER"),
}
}
}
impl NntpCommand for Over {}
#[derive(Clone, Copy, Debug)]
pub struct Quit;
impl fmt::Display for Quit {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "QUIT")
}
}
impl NntpCommand for Quit {}
#[derive(Clone, Debug)]
pub enum Stat {
MessageId(String),
Number(ArticleNumber),
Current,
}
impl fmt::Display for Stat {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Stat::MessageId(id) => write!(f, "STAT {}", id),
Stat::Number(num) => write!(f, "STAT {}", num),
Stat::Current => write!(f, "STAT"),
}
}
}
impl NntpCommand for Stat {}