use core::fmt;
pub mod get;
#[derive(Debug, Clone)]
pub struct Login<'a> {
pub protocol: u8,
pub client: &'static str,
pub clientver: f32,
pub creds: Option<(&'a str, &'a str)>
}
impl<'a> Default for Login<'a> {
#[inline]
fn default() -> Self {
Self::new(None)
}
}
impl<'a> Login<'a> {
pub fn new(creds: Option<(&'a str, &'a str)>) -> Self {
Login {
protocol: 1,
client: "rusty",
clientver: 0.1,
creds,
}
}
}
impl<'a> fmt::Display for Login<'a> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "login {{\"protocol\":{},\"client\":\"{}\",\"clientver\":{}", self.protocol, self.client, self.clientver)?;
match self.creds.as_ref() {
Some((ref login, ref password)) => write!(f, ",\"username\":\"{}\",\"password\":\"{}\"}}", login, password),
_ => write!(f, "}}"),
}
}
}
#[derive(Clone)]
pub struct Get<'a> {
pub kind: get::Type,
pub flags: get::Flags,
pub filters: get::Filters,
pub options: Option<get::Options<'a>>
}
impl<'a> fmt::Display for Get<'a> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "get {} {} {}", self.kind, self.flags, self.filters)?;
match self.options {
Some(ref options) => {
write!(f, " {}", options)
},
None => Ok(()),
}
}
}