From 3601bf6433d46dea4dd1960f7a3cdc514602983d Mon Sep 17 00:00:00 2001 From: Andy Wortman Date: Sat, 11 Nov 2017 03:33:40 -0800 Subject: move id formatting into a Display impl --- src/tw/mod.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'src/tw') 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::*; -- cgit v1.1