Skip to content

Commit

Permalink
Use an implicit impl instead of get_name.
Browse files Browse the repository at this point in the history
  • Loading branch information
musically-ut committed Mar 31, 2017
1 parent b75a585 commit 897e0e3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
12 changes: 7 additions & 5 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,22 +88,24 @@ fn write_timezone_file(timezone_file: &mut File, table: &Table) {
}}\n\n").unwrap();

write!(timezone_file,
"pub fn get_name(tz: &Tz) -> &'static str {{
match *tz {{\n").unwrap();
"impl Tz {{
pub fn name(self: &Tz) -> &'static str {{
match *self {{\n").unwrap();
for zone in &zones {
let zone_name = convert_bad_chars(zone);
write!(timezone_file,
" Tz::{zone} => \"{raw_zone_name}\",\n",
" Tz::{zone} => \"{raw_zone_name}\",\n",
zone = zone_name,
raw_zone_name = zone).unwrap();
}
write!(timezone_file,
" }}
" }}
}}
}}\n\n").unwrap();
write!(timezone_file,
"impl Debug for Tz {{
fn fmt(&self, f: &mut Formatter) -> Result<(), Error> {{
write!(f, \"{{}}\", get_name(&self))
write!(f, \"{{}}\", self.name())
}}
}}\n\n").unwrap();
write!(timezone_file,
Expand Down
11 changes: 5 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ mod timezones;
mod directory;

pub use directory::*;
pub use timezones::{Tz, get_name};
pub use timezones::Tz;

#[cfg(test)]
mod tests {
Expand All @@ -166,7 +166,6 @@ mod tests {
use super::Pacific::Tahiti;
use super::US::Eastern;
use super::Tz;
use super::get_name;
use chrono::{TimeZone, Duration};

#[test]
Expand Down Expand Up @@ -367,9 +366,9 @@ mod tests {

#[test]
fn test_get_name() {
assert_eq!(get_name(&London), "Europe/London");
assert_eq!(get_name(&Tz::Africa__Abidjan), "Africa/Abidjan");
assert_eq!(get_name(&Tz::UTC), "UTC");
assert_eq!(get_name(&Tz::Zulu), "Zulu");
assert_eq!(London.name(), "Europe/London");
assert_eq!(Tz::Africa__Abidjan.name(), "Africa/Abidjan");
assert_eq!(Tz::UTC.name(), "UTC");
assert_eq!(Tz::Zulu.name(), "Zulu");
}
}

0 comments on commit 897e0e3

Please sign in to comment.