Skip to content

Commit

Permalink
Update example in table module
Browse files Browse the repository at this point in the history
  • Loading branch information
pitdicker committed Apr 15, 2024
1 parent 56887a9 commit 31072df
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
4 changes: 2 additions & 2 deletions parse-zoneinfo/src/line.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1192,7 +1192,7 @@ impl LineParser {
})
}

pub fn parse_zone<'a>(&self, input: &'a str) -> Result<Zone<'a>, Error> {
fn parse_zone<'a>(&self, input: &'a str) -> Result<Zone<'a>, Error> {
if let Some(caps) = self.zone_line.captures(input) {
let name = caps.name("name").unwrap().as_str();
let info = self.zoneinfo_from_captures(caps)?;
Expand All @@ -1202,7 +1202,7 @@ impl LineParser {
}
}

pub fn parse_link<'a>(&self, input: &'a str) -> Result<Link<'a>, Error> {
fn parse_link<'a>(&self, input: &'a str) -> Result<Link<'a>, Error> {
if let Some(caps) = self.link_line.captures(input) {
let target = caps.name("target").unwrap().as_str();
let name = caps.name("name").unwrap().as_str();
Expand Down
24 changes: 17 additions & 7 deletions parse-zoneinfo/src/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,31 @@
//! ## Example
//!
//! ```
//! use parse_zoneinfo::line::{Zone, Link, LineParser};
//! use parse_zoneinfo::line::{Zone, Line, LineParser, Link};
//! use parse_zoneinfo::table::{TableBuilder};
//!
//! let parser = LineParser::new();
//! let zone = parser.parse_zone("Zone Pacific/Auckland 11:39:04 - LMT 1868 Nov 2").unwrap();
//! let link = parser.parse_link("Link Pacific/Auckland Antarctica/McMurdo").unwrap();
//!
//! let parser = LineParser::default();
//! let mut builder = TableBuilder::new();
//! builder.add_zone_line(zone).unwrap();
//! builder.add_link_line(link).unwrap();
//!
//! let zone = "Zone Pacific/Auckland 11:39:04 - LMT 1868 Nov 2";
//! let link = "Link Pacific/Auckland Antarctica/McMurdo";
//!
//! for line in [zone, link] {
//! match parser.parse_str(&line)? {
//! Line::Zone(zone) => builder.add_zone_line(zone).unwrap(),
//! Line::Continuation(cont) => builder.add_continuation_line(cont).unwrap(),
//! Line::Rule(rule) => builder.add_rule_line(rule).unwrap(),
//! Line::Link(link) => builder.add_link_line(link).unwrap(),
//! Line::Space => {}
//! }
//! }
//!
//! let table = builder.build();
//!
//! assert!(table.get_zoneset("Pacific/Auckland").is_some());
//! assert!(table.get_zoneset("Antarctica/McMurdo").is_some());
//! assert!(table.get_zoneset("UTC").is_none());
//! # Ok::<(), parse_zoneinfo::line::Error>(())
//! ```
use std::collections::hash_map::{Entry, HashMap};
Expand Down

0 comments on commit 31072df

Please sign in to comment.