aboutsummaryrefslogtreecommitdiff
path: root/src/tw
diff options
context:
space:
mode:
authoriximeow <me@iximeow.net>2017-11-11 03:33:40 -0800
committeriximeow <me@iximeow.net>2017-11-11 03:33:40 -0800
commite6091834b942f0c08c87a27223721c45795da627 (patch)
tree5d7d057480b0dc186311cd729f7a2c514a8c52eb /src/tw
parent1277e05c931608f7f07a41dff6bae92b8d262299 (diff)
move id formatting into a Display impl
Diffstat (limited to 'src/tw')
-rw-r--r--src/tw/mod.rs20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/tw/mod.rs b/src/tw/mod.rs
index e2b8b03..b5ad72b 100644
--- a/src/tw/mod.rs
+++ b/src/tw/mod.rs
@@ -1,4 +1,5 @@
use std::path::Path;
+use std::fmt;
use std::str::FromStr;
use std::fs::File;
use std::io::{BufRead, BufReader, Read};
@@ -167,6 +168,25 @@ pub enum TweetId {
Twitter(String) // twitter::number
}
+impl fmt::Display for TweetId {
+ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+ match self {
+ &TweetId::Today(ref id) => {
+ write!(f, "{}", id)
+ },
+ &TweetId::Dated(ref date, ref id) => {
+ write!(f, "{}:{}", date, id)
+ },
+ &TweetId::Bare(ref id) => {
+ write!(f, ":{}", id)
+ },
+ &TweetId::Twitter(ref id) => {
+ write!(f, "twitter:{}", id)
+ }
+ }
+ }
+}
+
#[cfg(test)]
mod tests {
use super::*;