aboutsummaryrefslogtreecommitdiff
path: root/src/event.rs
diff options
context:
space:
mode:
authorTill Höppner2016-02-23 17:00:53 +0100
committerTill Höppner2016-02-24 18:36:04 +0100
commitf01c278a26e0f248d188c10bdb852b0859b98b3b (patch)
tree3e729bf243011111a20b84f24aea3fbcb9f595f5 /src/event.rs
parent815f31f5cef61709c50087c9f7601ea330929bb7 (diff)
downloadilc-f01c278a26e0f248d188c10bdb852b0859b98b3b.tar.gz
ilc-f01c278a26e0f248d188c10bdb852b0859b98b3b.tar.xz
ilc-f01c278a26e0f248d188c10bdb852b0859b98b3b.zip
Test CI
Diffstat (limited to 'src/event.rs')
-rw-r--r--src/event.rs73
1 files changed, 44 insertions, 29 deletions
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<Event<'a>>
+ pub entries: Vec<Event<'a>>,
}
/// 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<Cow<'a, str>>
+ pub channel: Option<Cow<'a, str>>,
}
#[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<Cow<'a, str>>,
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<H>(&self, state: &mut H) where H: Hasher {
+ fn hash<H>(&self, state: &mut H)
+ where H: Hasher
+ {
self.0.ty.hash(state);
self.0.channel.hash(state);
}