From e866dceae987acd51d43bd457351bd2188c5f95a Mon Sep 17 00:00:00 2001 From: Till Höppner Date: Tue, 23 Feb 2016 17:00:53 +0100 Subject: Test CI --- src/event.rs | 73 ++++++++++++++++++++++++++++++++++++------------------------ 1 file changed, 44 insertions(+), 29 deletions(-) (limited to 'src/event.rs') diff --git a/src/event.rs b/src/event.rs index d2ce053..0a6fb2b 100644 --- a/src/event.rs +++ b/src/event.rs @@ -17,7 +17,7 @@ use std::borrow::Cow; use std::cmp::Ordering; -use std::hash::{ Hash, Hasher }; +use std::hash::{Hash, Hasher}; use chrono::naive::time::NaiveTime; use chrono::offset::fixed::FixedOffset; @@ -27,7 +27,7 @@ use chrono::offset::TimeZone; /// A whole log, in memory. This structure does not specify its /// use. It may represent a private query, or the log of a channel. pub struct Log<'a> { - pub entries: Vec> + pub entries: Vec>, } /// Different log formats carry different amounts of information. Some might @@ -37,23 +37,25 @@ pub struct Log<'a> { pub enum Time { Unknown, Hms(u8, u8, u8), - Timestamp(i64) + Timestamp(i64), } impl Time { pub fn from_format(tz: &FixedOffset, s: &str, f: &str) -> Time { tz.datetime_from_str(s, f) - .map(|d| d.timestamp()) - .map(Time::Timestamp) - .unwrap_or(Time::Unknown) + .map(|d| d.timestamp()) + .map(Time::Timestamp) + .unwrap_or(Time::Unknown) } pub fn with_format(&self, tz: &FixedOffset, f: &str) -> String { match self { &Time::Unknown => panic!("Time data for this event is not present"), - &Time::Hms(h, m, s) => format!("{}", - NaiveTime::from_hms(h as u32, m as u32, s as u32).format(f)), - &Time::Timestamp(t) => format!("{}", tz.timestamp(t, 0).format(f)) + &Time::Hms(h, m, s) => { + format!("{}", + NaiveTime::from_hms(h as u32, m as u32, s as u32).format(f)) + } + &Time::Timestamp(t) => format!("{}", tz.timestamp(t, 0).format(f)), } } @@ -61,14 +63,18 @@ impl Time { use self::Time::*; match self { &Unknown => 0, - &Hms(h, m, s) => Local::today() - .and_hms(h as u32, m as u32, s as u32) - .timestamp(), - &Timestamp(i) => i + &Hms(h, m, s) => { + Local::today() + .and_hms(h as u32, m as u32, s as u32) + .timestamp() + } + &Timestamp(i) => i, } } - pub fn to_timestamp(&self) -> Time { Time::Timestamp(self.as_timestamp()) } + pub fn to_timestamp(&self) -> Time { + Time::Timestamp(self.as_timestamp()) + } } impl PartialOrd for Time { @@ -77,13 +83,16 @@ impl PartialOrd for Time { match (self, other) { (&Unknown, _) | (_, &Unknown) => None, (&Hms(a_h, a_m, a_s), &Hms(b_h, b_m, b_s)) => { - if (a_h >= b_h && a_m >= b_m && a_s > b_s) - || (a_h >= b_h && a_m > b_m && a_s >= b_s) - || (a_h > b_h && a_m >= b_m && a_s >= b_s) - { Some(Ordering::Greater) } else { Some(Ordering::Less) } - }, + if (a_h >= b_h && a_m >= b_m && a_s > b_s) || + (a_h >= b_h && a_m > b_m && a_s >= b_s) || + (a_h > b_h && a_m >= b_m && a_s >= b_s) { + Some(Ordering::Greater) + } else { + Some(Ordering::Less) + } + } (&Timestamp(a), &Timestamp(b)) => Some(a.cmp(&b)), - _ => unimplemented!() + _ => unimplemented!(), } } } @@ -92,12 +101,12 @@ impl PartialOrd for Time { pub struct Event<'a> { pub ty: Type<'a>, pub time: Time, - pub channel: Option> + pub channel: Option>, } #[derive(Clone, Debug, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable)] pub struct User<'a> { - nick: Cow<'a, str> + nicks: Cow<'a, str>, } /// All representable events, such as messages, quits, joins @@ -151,8 +160,8 @@ pub enum Type<'a> { Mode { nick: Option>, mode: Cow<'a, str>, - masks: Cow<'a, str> - } + masks: Cow<'a, str>, + }, } impl<'a> Type<'a> { @@ -166,11 +175,15 @@ impl<'a> Type<'a> { &Quit { ref nick, .. } => nick == needle, &Nick { ref old_nick, ref new_nick, .. } => old_nick == needle || new_nick == needle, &Notice { ref from, .. } => from == needle, - &Kick { ref kicked_nick, ref kicking_nick, .. } => *kicked_nick == Cow::Borrowed(needle) - || kicking_nick.as_ref().map_or(false, |k| k.as_ref() == Cow::Borrowed(needle)), + &Kick { ref kicked_nick, ref kicking_nick, .. } => { + *kicked_nick == Cow::Borrowed(needle) || + kicking_nick.as_ref().map_or(false, |k| k.as_ref() == Cow::Borrowed(needle)) + } &TopicChange { ref nick, .. } => nick.as_ref().map_or(false, |k| k.as_ref() == needle), - &Mode { ref nick, .. } => nick.as_ref().map_or(false, |k| k.as_ref() == Cow::Borrowed(needle)), - _ => false + &Mode { ref nick, .. } => { + nick.as_ref().map_or(false, |k| k.as_ref() == Cow::Borrowed(needle)) + } + _ => false, } } } @@ -179,7 +192,9 @@ impl<'a> Type<'a> { pub struct NoTimeHash<'a>(pub Event<'a>); impl<'a> Hash for NoTimeHash<'a> { - fn hash(&self, state: &mut H) where H: Hasher { + fn hash(&self, state: &mut H) + where H: Hasher + { self.0.ty.hash(state); self.0.channel.hash(state); } -- cgit v1.2.3