use std::fmt::{Display, Formatter, Result as FmtResult};
pub struct ListingOptions {
pub batch: u8,
pub anchor: ListingAnchor
}
impl Display for ListingOptions {
fn fmt(&self, f: &mut Formatter) -> FmtResult {
write!(f, "limit={}", self.batch)
}
}
impl ListingOptions {
pub fn default() -> ListingOptions {
ListingOptions {
batch: 25,
anchor: ListingAnchor::None
}
}
}
pub enum ListingAnchor {
After(String),
Before(String),
None
}
impl Display for ListingAnchor {
fn fmt(&self, f: &mut Formatter) -> FmtResult {
match *self {
ListingAnchor::Before(ref pos) => write!(f, "before={}", pos),
ListingAnchor::After(ref pos) => write!(f, "after={}", pos),
ListingAnchor::None => Ok(())
}
}
}
#[allow(missing_docs)]
pub enum TimeFilter {
Hour,
Day,
Week,
Month,
Year,
AllTime,
}
impl Display for TimeFilter {
fn fmt(&self, f: &mut Formatter) -> FmtResult {
let s = match *self {
TimeFilter::Hour => "hour",
TimeFilter::Day => "day",
TimeFilter::Week => "week",
TimeFilter::Month => "month",
TimeFilter::Year => "year",
TimeFilter::AllTime => "all",
};
write!(f, "&t={}", s)
}
}
pub struct LinkPost {
pub title: String,
pub link: String,
pub resubmit: bool
}
impl LinkPost {
pub fn new(title: &str, link: &str) -> LinkPost {
LinkPost {
title: title.to_owned(),
link: link.to_owned(),
resubmit: false
}
}
pub fn resubmit(mut self) -> LinkPost {
self.resubmit = true;
self
}
}
pub struct SelfPost {
pub title: String,
pub text: String
}
impl SelfPost {
pub fn new(title: &str, text: &str) -> SelfPost {
SelfPost {
title: title.to_owned(),
text: text.to_owned()
}
}
}