| 1 | //! Collecting parsed zoneinfo data lines into a set of time zone data. |
| 2 | //! |
| 3 | //! This module provides the `Table` struct, which is able to take parsed |
| 4 | //! lines of input from the `line` module and coalesce them into a single |
| 5 | //! set of data. |
| 6 | //! |
| 7 | //! It’s not as simple as it seems, because the zoneinfo data lines refer to |
| 8 | //! each other through strings: lines of the form “link zone A to B” could be |
| 9 | //! *parsed* successfully but still fail to be *interpreted* successfully if |
| 10 | //! “B” doesn’t exist. So it has to check every step of the way—nothing wrong |
| 11 | //! with this, it’s just a consequence of reading data from a text file. |
| 12 | //! |
| 13 | //! This module only deals with constructing a table from data: any analysis |
| 14 | //! of the data is done elsewhere. |
| 15 | //! |
| 16 | //! |
| 17 | //! ## Example |
| 18 | //! |
| 19 | //! ``` |
| 20 | //! use parse_zoneinfo::line::{Zone, Line, Link}; |
| 21 | //! use parse_zoneinfo::table::TableBuilder; |
| 22 | //! |
| 23 | //! let mut builder = TableBuilder::new(); |
| 24 | //! |
| 25 | //! let zone = "Zone Pacific/Auckland 11:39:04 - LMT 1868 Nov 2"; |
| 26 | //! let link = "Link Pacific/Auckland Antarctica/McMurdo"; |
| 27 | //! |
| 28 | //! for line in [zone, link] { |
| 29 | //! builder.add_line(Line::new(&line)?).unwrap(); |
| 30 | //! } |
| 31 | //! |
| 32 | //! let table = builder.build(); |
| 33 | //! |
| 34 | //! assert!(table.get_zoneset("Pacific/Auckland").is_some()); |
| 35 | //! assert!(table.get_zoneset("Antarctica/McMurdo").is_some()); |
| 36 | //! assert!(table.get_zoneset("UTC").is_none()); |
| 37 | //! # Ok::<(), parse_zoneinfo::line::Error>(()) |
| 38 | //! ``` |
| 39 | |
| 40 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::collectionsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/::hash_maprust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash_map/::{Entryrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/Entry#, HashMaprust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/HashMap#}; |
| 41 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::{selfrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/, Writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Write#}; |
| 42 | |
| 43 | use craterust-analyzer cargo parse-zoneinfo 0.5.0 crate/::linerust-analyzer cargo parse-zoneinfo 0.5.0 line/::{selfrust-analyzer cargo parse-zoneinfo 0.5.0 line/, ChangeTimerust-analyzer cargo parse-zoneinfo 0.5.0 line/ChangeTime#, DaySpecrust-analyzer cargo parse-zoneinfo 0.5.0 line/DaySpec#, Linerust-analyzer cargo parse-zoneinfo 0.5.0 line/Line#, Monthrust-analyzer cargo parse-zoneinfo 0.5.0 line/Month#, TimeTyperust-analyzer cargo parse-zoneinfo 0.5.0 line/TimeType#, Yearrust-analyzer cargo parse-zoneinfo 0.5.0 line/Year#}; |
| 44 | |
| 45 | /// A **table** of all the data in one or more zoneinfo files. |
| 46 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default:)] |
| 47 | pub struct Tablerust-analyzer cargo parse-zoneinfo 0.5.0 table/Table# { |
| 48 | /// Mapping of ruleset names to rulesets. |
| 49 | pub rulesetsrust-analyzer cargo parse-zoneinfo 0.5.0 table/Table#rulesets.: HashMaprust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/HashMap#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<RuleInforust-analyzer cargo parse-zoneinfo 0.5.0 table/RuleInfo#>>, |
| 50 | |
| 51 | /// Mapping of zoneset names to zonesets. |
| 52 | pub zonesetsrust-analyzer cargo parse-zoneinfo 0.5.0 table/Table#zonesets.: HashMaprust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/HashMap#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<ZoneInforust-analyzer cargo parse-zoneinfo 0.5.0 table/ZoneInfo#>>, |
| 53 | |
| 54 | /// Mapping of link timezone names, to the names they link to. |
| 55 | pub linksrust-analyzer cargo parse-zoneinfo 0.5.0 table/Table#links.: HashMaprust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/HashMap#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>, |
| 56 | } |
| 57 | |
| 58 | impl Tablerust-analyzer cargo parse-zoneinfo 0.5.0 table/Table# { |
| 59 | /// Tries to find the zoneset with the given name by looking it up in |
| 60 | /// either the zonesets map or the links map. |
| 61 | pub fn get_zonesetrust-analyzer cargo parse-zoneinfo 0.5.0 table/impl#[Table]get_zoneset().(&self, zone_name: &str) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&[ZoneInforust-analyzer cargo parse-zoneinfo 0.5.0 table/ZoneInfo#]> { |
| 62 | if self.zonesetsrust-analyzer cargo parse-zoneinfo 0.5.0 table/Table#zonesets..contains_keyrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]contains_key().(zone_name) { |
| 63 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(&*rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][Deref]deref().self.zonesetsrust-analyzer cargo parse-zoneinfo 0.5.0 table/Table#zonesets.[rust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`][`Index<&Q>`]index().zone_name]rust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`][`Index<&Q>`]index().) |
| 64 | } else if self.linksrust-analyzer cargo parse-zoneinfo 0.5.0 table/Table#links..contains_keyrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]contains_key().(zone_name) { |
| 65 | let target = &self.linksrust-analyzer cargo parse-zoneinfo 0.5.0 table/Table#links.[rust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`][`Index<&Q>`]index().zone_name]rust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`][`Index<&Q>`]index().; |
| 66 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(&*rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][Deref]deref().self.zonesetsrust-analyzer cargo parse-zoneinfo 0.5.0 table/Table#zonesets.[rust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`][`Index<&Q>`]index().target]rust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`][`Index<&Q>`]index().) |
| 67 | } else { |
| 68 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# |
| 69 | } |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | /// An owned rule definition line. |
| 74 | /// |
| 75 | /// This mimics the `Rule` struct in the `line` module, only its uses owned |
| 76 | /// Strings instead of string slices, and has had some pre-processing |
| 77 | /// applied to it. |
| 78 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:)] |
| 79 | pub struct RuleInforust-analyzer cargo parse-zoneinfo 0.5.0 table/RuleInfo# { |
| 80 | /// The year that this rule *starts* applying. |
| 81 | pub from_yearrust-analyzer cargo parse-zoneinfo 0.5.0 table/RuleInfo#from_year.: Yearrust-analyzer cargo parse-zoneinfo 0.5.0 line/Year#, |
| 82 | |
| 83 | /// The year that this rule *finishes* applying, inclusive, or `None` if |
| 84 | /// it applies up until the end of this timespan. |
| 85 | pub to_yearrust-analyzer cargo parse-zoneinfo 0.5.0 table/RuleInfo#to_year.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Yearrust-analyzer cargo parse-zoneinfo 0.5.0 line/Year#>, |
| 86 | |
| 87 | /// The month it applies on. |
| 88 | pub monthrust-analyzer cargo parse-zoneinfo 0.5.0 table/RuleInfo#month.: Monthrust-analyzer cargo parse-zoneinfo 0.5.0 line/Month#, |
| 89 | |
| 90 | /// The day it applies on. |
| 91 | pub dayrust-analyzer cargo parse-zoneinfo 0.5.0 table/RuleInfo#day.: DaySpecrust-analyzer cargo parse-zoneinfo 0.5.0 line/DaySpec#, |
| 92 | |
| 93 | /// The exact time it applies on. |
| 94 | pub timerust-analyzer cargo parse-zoneinfo 0.5.0 table/RuleInfo#time.: i64, |
| 95 | |
| 96 | /// The type of time that time is. |
| 97 | pub time_typerust-analyzer cargo parse-zoneinfo 0.5.0 table/RuleInfo#time_type.: TimeTyperust-analyzer cargo parse-zoneinfo 0.5.0 line/TimeType#, |
| 98 | |
| 99 | /// The amount of time to save. |
| 100 | pub time_to_addrust-analyzer cargo parse-zoneinfo 0.5.0 table/RuleInfo#time_to_add.: i64, |
| 101 | |
| 102 | /// Any extra letters that should be added to this time zone’s |
| 103 | /// abbreviation, in place of `%s`. |
| 104 | pub lettersrust-analyzer cargo parse-zoneinfo 0.5.0 table/RuleInfo#letters.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>, |
| 105 | } |
| 106 | |
| 107 | impl<'line> Fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/From#<linerust-analyzer cargo parse-zoneinfo 0.5.0 line/::Rulerust-analyzer cargo parse-zoneinfo 0.5.0 line/Rule#<'line>> for RuleInforust-analyzer cargo parse-zoneinfo 0.5.0 table/RuleInfo# { |
| 108 | fn fromrust-analyzer cargo parse-zoneinfo 0.5.0 table/impl#[RuleInfo][`From<line::Rule<'line>>`]from().(info: linerust-analyzer cargo parse-zoneinfo 0.5.0 line/::Rulerust-analyzer cargo parse-zoneinfo 0.5.0 line/Rule#) -> RuleInforust-analyzer cargo parse-zoneinfo 0.5.0 table/RuleInfo# { |
| 109 | RuleInforust-analyzer cargo parse-zoneinfo 0.5.0 table/RuleInfo# { |
| 110 | from_yearrust-analyzer cargo parse-zoneinfo 0.5.0 table/RuleInfo#from_year.: info.from_yearrust-analyzer cargo parse-zoneinfo 0.5.0 line/Rule#from_year., |
| 111 | to_yearrust-analyzer cargo parse-zoneinfo 0.5.0 table/RuleInfo#to_year.: info.to_yearrust-analyzer cargo parse-zoneinfo 0.5.0 line/Rule#to_year., |
| 112 | monthrust-analyzer cargo parse-zoneinfo 0.5.0 table/RuleInfo#month.: info.monthrust-analyzer cargo parse-zoneinfo 0.5.0 line/Rule#month., |
| 113 | dayrust-analyzer cargo parse-zoneinfo 0.5.0 table/RuleInfo#day.: info.dayrust-analyzer cargo parse-zoneinfo 0.5.0 line/Rule#day., |
| 114 | timerust-analyzer cargo parse-zoneinfo 0.5.0 table/RuleInfo#time.: info.timerust-analyzer cargo parse-zoneinfo 0.5.0 line/Rule#time..0rust-analyzer cargo parse-zoneinfo 0.5.0 line/TimeSpecAndType#0..as_secondsrust-analyzer cargo parse-zoneinfo 0.5.0 line/impl#[TimeSpec]as_seconds().(), |
| 115 | time_typerust-analyzer cargo parse-zoneinfo 0.5.0 table/RuleInfo#time_type.: info.timerust-analyzer cargo parse-zoneinfo 0.5.0 line/Rule#time..1rust-analyzer cargo parse-zoneinfo 0.5.0 line/TimeSpecAndType#1., |
| 116 | time_to_addrust-analyzer cargo parse-zoneinfo 0.5.0 table/RuleInfo#time_to_add.: info.time_to_addrust-analyzer cargo parse-zoneinfo 0.5.0 line/Rule#time_to_add..as_secondsrust-analyzer cargo parse-zoneinfo 0.5.0 line/impl#[TimeSpec]as_seconds().(), |
| 117 | lettersrust-analyzer cargo parse-zoneinfo 0.5.0 table/RuleInfo#letters.: info.lettersrust-analyzer cargo parse-zoneinfo 0.5.0 line/Rule#letters..maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(str::to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().), |
| 118 | } |
| 119 | } |
| 120 | } |
| 121 | |
| 122 | impl RuleInforust-analyzer cargo parse-zoneinfo 0.5.0 table/RuleInfo# { |
| 123 | /// Returns whether this rule is in effect during the given year. |
| 124 | pub fn applies_to_yearrust-analyzer cargo parse-zoneinfo 0.5.0 table/impl#[RuleInfo]applies_to_year().(&self, year: i64) -> bool { |
| 125 | use linerust-analyzer cargo parse-zoneinfo 0.5.0 line/::Yearrust-analyzer cargo parse-zoneinfo 0.5.0 line/Year#::*; |
| 126 | |
| 127 | match (self.from_yearrust-analyzer cargo parse-zoneinfo 0.5.0 table/RuleInfo#from_year., self.to_yearrust-analyzer cargo parse-zoneinfo 0.5.0 table/RuleInfo#to_year.) { |
| 128 | (Numberrust-analyzer cargo parse-zoneinfo 0.5.0 line/Year#Number#(from), Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#) => year rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i64][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i64][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i64][`PartialEq<Self>`]eq().from, |
| 129 | (Numberrust-analyzer cargo parse-zoneinfo 0.5.0 line/Year#Number#(from), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Maximumrust-analyzer cargo parse-zoneinfo 0.5.0 line/Year#Maximum#)) => year rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i64][`PartialOrd<Self>`]ge().>=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i64][`PartialOrd<Self>`]ge(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i64][`PartialOrd<Self>`]ge().from, |
| 130 | (Numberrust-analyzer cargo parse-zoneinfo 0.5.0 line/Year#Number#(from), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Numberrust-analyzer cargo parse-zoneinfo 0.5.0 line/Year#Number#(to))) => year rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i64][`PartialOrd<Self>`]ge().>=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i64][`PartialOrd<Self>`]ge(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i64][`PartialOrd<Self>`]ge().from && year rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i64][`PartialOrd<Self>`]le().<=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i64][`PartialOrd<Self>`]le(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i64][`PartialOrd<Self>`]le().to, |
| 131 | _ => unreachablerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/unreachable!!(), |
| 132 | } |
| 133 | } |
| 134 | |
| 135 | pub fn absolute_datetimerust-analyzer cargo parse-zoneinfo 0.5.0 table/impl#[RuleInfo]absolute_datetime().(&self, year: i64, utc_offset: i64, dst_offset: i64) -> i64 { |
| 136 | let offset = match self.time_typerust-analyzer cargo parse-zoneinfo 0.5.0 table/RuleInfo#time_type. { |
| 137 | TimeTyperust-analyzer cargo parse-zoneinfo 0.5.0 line/TimeType#::UTCrust-analyzer cargo parse-zoneinfo 0.5.0 line/TimeType#UTC# => 0, |
| 138 | TimeTyperust-analyzer cargo parse-zoneinfo 0.5.0 line/TimeType#::Standardrust-analyzer cargo parse-zoneinfo 0.5.0 line/TimeType#Standard# => utc_offset, |
| 139 | TimeTyperust-analyzer cargo parse-zoneinfo 0.5.0 line/TimeType#::Wallrust-analyzer cargo parse-zoneinfo 0.5.0 line/TimeType#Wall# => utc_offset rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][`Add<Self>`]add().dst_offset, |
| 140 | }; |
| 141 | |
| 142 | let changetime = ChangeTimerust-analyzer cargo parse-zoneinfo 0.5.0 line/ChangeTime#::UntilDayrust-analyzer cargo parse-zoneinfo 0.5.0 line/ChangeTime#UntilDay#(Yearrust-analyzer cargo parse-zoneinfo 0.5.0 line/Year#::Numberrust-analyzer cargo parse-zoneinfo 0.5.0 line/Year#Number#(year), self.monthrust-analyzer cargo parse-zoneinfo 0.5.0 table/RuleInfo#month., self.dayrust-analyzer cargo parse-zoneinfo 0.5.0 table/RuleInfo#day.); |
| 143 | let unused = 0; |
| 144 | changetime.to_timestamprust-analyzer cargo parse-zoneinfo 0.5.0 line/impl#[ChangeTime]to_timestamp().(unused, unused) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][`Add<Self>`]add().self.timerust-analyzer cargo parse-zoneinfo 0.5.0 table/RuleInfo#time. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][`Sub<Self>`]sub().offset |
| 145 | } |
| 146 | } |
| 147 | |
| 148 | /// An owned zone definition line. |
| 149 | /// |
| 150 | /// This struct mimics the `ZoneInfo` struct in the `line` module, *not* the |
| 151 | /// `Zone` struct, which is the key name in the map—this is just the value. |
| 152 | /// |
| 153 | /// As with `RuleInfo`, this struct uses owned Strings rather than string |
| 154 | /// slices. |
| 155 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:)] |
| 156 | pub struct ZoneInforust-analyzer cargo parse-zoneinfo 0.5.0 table/ZoneInfo# { |
| 157 | /// The number of seconds that need to be added to UTC to get the |
| 158 | /// standard time in this zone. |
| 159 | pub offsetrust-analyzer cargo parse-zoneinfo 0.5.0 table/ZoneInfo#offset.: i64, |
| 160 | |
| 161 | /// The name of all the rules that should apply in the time zone, or the |
| 162 | /// amount of daylight-saving time to add. |
| 163 | pub savingrust-analyzer cargo parse-zoneinfo 0.5.0 table/ZoneInfo#saving.: Savingrust-analyzer cargo parse-zoneinfo 0.5.0 table/Saving#, |
| 164 | |
| 165 | /// The format for time zone abbreviations. |
| 166 | pub formatrust-analyzer cargo parse-zoneinfo 0.5.0 table/ZoneInfo#format.: Formatrust-analyzer cargo parse-zoneinfo 0.5.0 table/Format#, |
| 167 | |
| 168 | /// The time at which the rules change for this time zone, or `None` if |
| 169 | /// these rules are in effect until the end of time (!). |
| 170 | pub end_timerust-analyzer cargo parse-zoneinfo 0.5.0 table/ZoneInfo#end_time.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<ChangeTimerust-analyzer cargo parse-zoneinfo 0.5.0 line/ChangeTime#>, |
| 171 | } |
| 172 | |
| 173 | impl<'line> Fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/From#<linerust-analyzer cargo parse-zoneinfo 0.5.0 line/::ZoneInforust-analyzer cargo parse-zoneinfo 0.5.0 line/ZoneInfo#<'line>> for ZoneInforust-analyzer cargo parse-zoneinfo 0.5.0 table/ZoneInfo# { |
| 174 | fn fromrust-analyzer cargo parse-zoneinfo 0.5.0 table/impl#[ZoneInfo][`From<line::ZoneInfo<'line>>`]from().(info: linerust-analyzer cargo parse-zoneinfo 0.5.0 line/::ZoneInforust-analyzer cargo parse-zoneinfo 0.5.0 line/ZoneInfo#) -> ZoneInforust-analyzer cargo parse-zoneinfo 0.5.0 table/ZoneInfo# { |
| 175 | ZoneInforust-analyzer cargo parse-zoneinfo 0.5.0 table/ZoneInfo# { |
| 176 | offsetrust-analyzer cargo parse-zoneinfo 0.5.0 table/ZoneInfo#offset.: info.utc_offsetrust-analyzer cargo parse-zoneinfo 0.5.0 line/ZoneInfo#utc_offset..as_secondsrust-analyzer cargo parse-zoneinfo 0.5.0 line/impl#[TimeSpec]as_seconds().(), |
| 177 | savingrust-analyzer cargo parse-zoneinfo 0.5.0 table/ZoneInfo#saving.: match info.savingrust-analyzer cargo parse-zoneinfo 0.5.0 line/ZoneInfo#saving. { |
| 178 | linerust-analyzer cargo parse-zoneinfo 0.5.0 line/::Savingrust-analyzer cargo parse-zoneinfo 0.5.0 line/Saving#::NoSavingrust-analyzer cargo parse-zoneinfo 0.5.0 line/Saving#NoSaving# => Savingrust-analyzer cargo parse-zoneinfo 0.5.0 table/Saving#::NoSavingrust-analyzer cargo parse-zoneinfo 0.5.0 table/Saving#NoSaving#, |
| 179 | linerust-analyzer cargo parse-zoneinfo 0.5.0 line/::Savingrust-analyzer cargo parse-zoneinfo 0.5.0 line/Saving#::Multiplerust-analyzer cargo parse-zoneinfo 0.5.0 line/Saving#Multiple#(s) => Savingrust-analyzer cargo parse-zoneinfo 0.5.0 table/Saving#::Multiplerust-analyzer cargo parse-zoneinfo 0.5.0 table/Saving#Multiple#(s.to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().()), |
| 180 | linerust-analyzer cargo parse-zoneinfo 0.5.0 line/::Savingrust-analyzer cargo parse-zoneinfo 0.5.0 line/Saving#::OneOffrust-analyzer cargo parse-zoneinfo 0.5.0 line/Saving#OneOff#(t) => Savingrust-analyzer cargo parse-zoneinfo 0.5.0 table/Saving#::OneOffrust-analyzer cargo parse-zoneinfo 0.5.0 table/Saving#OneOff#(t.as_secondsrust-analyzer cargo parse-zoneinfo 0.5.0 line/impl#[TimeSpec]as_seconds().()), |
| 181 | }, |
| 182 | formatrust-analyzer cargo parse-zoneinfo 0.5.0 table/ZoneInfo#format.: Formatrust-analyzer cargo parse-zoneinfo 0.5.0 table/Format#::newrust-analyzer cargo parse-zoneinfo 0.5.0 table/impl#[Format]new().(info.formatrust-analyzer cargo parse-zoneinfo 0.5.0 line/ZoneInfo#format.), |
| 183 | end_timerust-analyzer cargo parse-zoneinfo 0.5.0 table/ZoneInfo#end_time.: info.timerust-analyzer cargo parse-zoneinfo 0.5.0 line/ZoneInfo#time., |
| 184 | } |
| 185 | } |
| 186 | } |
| 187 | |
| 188 | /// The amount of daylight saving time (DST) to apply to this timespan. This |
| 189 | /// is a special type for a certain field in a zone line, which can hold |
| 190 | /// different types of value. |
| 191 | /// |
| 192 | /// This is the owned version of the `Saving` type in the `line` module. |
| 193 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:)] |
| 194 | pub enum Savingrust-analyzer cargo parse-zoneinfo 0.5.0 table/Saving# { |
| 195 | /// Just stick to the base offset. |
| 196 | NoSavingrust-analyzer cargo parse-zoneinfo 0.5.0 table/Saving#NoSaving#, |
| 197 | |
| 198 | /// This amount of time should be saved while this timespan is in effect. |
| 199 | /// (This is the equivalent to there being a single one-off rule with the |
| 200 | /// given amount of time to save). |
| 201 | OneOffrust-analyzer cargo parse-zoneinfo 0.5.0 table/Saving#OneOff#(i64), |
| 202 | |
| 203 | /// All rules with the given name should apply while this timespan is in |
| 204 | /// effect. |
| 205 | Multiplerust-analyzer cargo parse-zoneinfo 0.5.0 table/Saving#Multiple#(Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#), |
| 206 | } |
| 207 | |
| 208 | /// The format string to generate a time zone abbreviation from. |
| 209 | #[non_exhaustive] |
| 210 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:)] |
| 211 | pub enum Formatrust-analyzer cargo parse-zoneinfo 0.5.0 table/Format# { |
| 212 | /// A constant format, which remains the same throughout both standard |
| 213 | /// and DST timespans. |
| 214 | Constantrust-analyzer cargo parse-zoneinfo 0.5.0 table/Format#Constant#(Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#), |
| 215 | |
| 216 | /// An alternate format, such as “PST/PDT”, which changes between |
| 217 | /// standard and DST timespans. |
| 218 | Alternaterust-analyzer cargo parse-zoneinfo 0.5.0 table/Format#Alternate# { |
| 219 | /// Abbreviation to use during Standard Time. |
| 220 | standardrust-analyzer cargo parse-zoneinfo 0.5.0 table/Format#Alternate#standard.: Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, |
| 221 | |
| 222 | /// Abbreviation to use during Summer Time. |
| 223 | dstrust-analyzer cargo parse-zoneinfo 0.5.0 table/Format#Alternate#dst.: Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, |
| 224 | }, |
| 225 | |
| 226 | /// A format with a placeholder `%s`, which uses the `letters` field in |
| 227 | /// a `RuleInfo` to generate the time zone abbreviation. |
| 228 | Placeholderrust-analyzer cargo parse-zoneinfo 0.5.0 table/Format#Placeholder#(Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#), |
| 229 | |
| 230 | /// The special %z placeholder that gets formatted as a numeric offset. |
| 231 | Offsetrust-analyzer cargo parse-zoneinfo 0.5.0 table/Format#Offset#, |
| 232 | } |
| 233 | |
| 234 | impl Formatrust-analyzer cargo parse-zoneinfo 0.5.0 table/Format# { |
| 235 | /// Convert the template into one of the `Format` variants. This can’t |
| 236 | /// fail, as any syntax that doesn’t match one of the two formats will |
| 237 | /// just be a ‘constant’ format. |
| 238 | pub fn newrust-analyzer cargo parse-zoneinfo 0.5.0 table/impl#[Format]new().(template: &str) -> Formatrust-analyzer cargo parse-zoneinfo 0.5.0 table/Format# { |
| 239 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(pos) = template.findrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]find().('/') { |
| 240 | Formatrust-analyzer cargo parse-zoneinfo 0.5.0 table/Format#::Alternaterust-analyzer cargo parse-zoneinfo 0.5.0 table/Format#Alternate# { |
| 241 | standardrust-analyzer cargo parse-zoneinfo 0.5.0 table/Format#Alternate#standard.: template[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeTo#pos]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()..to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().(), |
| 242 | dstrust-analyzer cargo parse-zoneinfo 0.5.0 table/Format#Alternate#dst.: template[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().pos rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().1..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFrom#]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()..to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().(), |
| 243 | } |
| 244 | } else if template.containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]contains().("%s") { |
| 245 | Formatrust-analyzer cargo parse-zoneinfo 0.5.0 table/Format#::Placeholderrust-analyzer cargo parse-zoneinfo 0.5.0 table/Format#Placeholder#(template.to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().()) |
| 246 | } else if template rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq()."%z" { |
| 247 | Formatrust-analyzer cargo parse-zoneinfo 0.5.0 table/Format#::Offsetrust-analyzer cargo parse-zoneinfo 0.5.0 table/Format#Offset# |
| 248 | } else { |
| 249 | Formatrust-analyzer cargo parse-zoneinfo 0.5.0 table/Format#::Constantrust-analyzer cargo parse-zoneinfo 0.5.0 table/Format#Constant#(template.to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().()) |
| 250 | } |
| 251 | } |
| 252 | |
| 253 | pub fn formatrust-analyzer cargo parse-zoneinfo 0.5.0 table/impl#[Format]format().(&self, utc_offset: i64, dst_offset: i64, letters: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>) -> Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String# { |
| 254 | let letters = match letters { |
| 255 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(l) => &*rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][Deref]deref().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().l, |
| 256 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => "", |
| 257 | }; |
| 258 | |
| 259 | match *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().self { |
| 260 | Formatrust-analyzer cargo parse-zoneinfo 0.5.0 table/Format#::Constantrust-analyzer cargo parse-zoneinfo 0.5.0 table/Format#Constant#(ref s) => s.clonerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][Clone]clone().(), |
| 261 | Formatrust-analyzer cargo parse-zoneinfo 0.5.0 table/Format#::Placeholderrust-analyzer cargo parse-zoneinfo 0.5.0 table/Format#Placeholder#(ref s) => s.replacerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str]replace().("%s", letters), |
| 262 | Formatrust-analyzer cargo parse-zoneinfo 0.5.0 table/Format#::Alternaterust-analyzer cargo parse-zoneinfo 0.5.0 table/Format#Alternate# { ref standardrust-analyzer cargo parse-zoneinfo 0.5.0 table/Format#Alternate#standard., .. } if dst_offset rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i64][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i64][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i64][`PartialEq<Self>`]eq().0 => standard.clonerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][Clone]clone().(), |
| 263 | Formatrust-analyzer cargo parse-zoneinfo 0.5.0 table/Format#::Alternaterust-analyzer cargo parse-zoneinfo 0.5.0 table/Format#Alternate# { ref dstrust-analyzer cargo parse-zoneinfo 0.5.0 table/Format#Alternate#dst., .. } => dst.clonerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][Clone]clone().(), |
| 264 | Formatrust-analyzer cargo parse-zoneinfo 0.5.0 table/Format#::Offsetrust-analyzer cargo parse-zoneinfo 0.5.0 table/Format#Offset# => { |
| 265 | let offset = utc_offset rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][`Add<Self>`]add().dst_offset; |
| 266 | let (sign, off) = if offset rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i64][`PartialOrd<Self>`]lt().<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i64][`PartialOrd<Self>`]lt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i64][`PartialOrd<Self>`]lt().0 { |
| 267 | ('-', -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][Neg]neg().offset) |
| 268 | } else { |
| 269 | ('+', offset) |
| 270 | }; |
| 271 | |
| 272 | let mut f = Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#::fromrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`From<char>`]from().(sign); |
| 273 | |
| 274 | let minutes = off rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][`Div<Self>`]div()./rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][`Div<Self>`]div(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][`Div<Self>`]div().60; |
| 275 | let secs = (off rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][`Rem<Self>`]rem().%rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][`Rem<Self>`]rem(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][`Rem<Self>`]rem().60) as u8; |
| 276 | let mins = (minutes rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][`Rem<Self>`]rem().%rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][`Rem<Self>`]rem(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][`Rem<Self>`]rem().60) as u8; |
| 277 | let hours = (minutes rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][`Div<Self>`]div()./rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][`Div<Self>`]div(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][`Div<Self>`]div().60) as u8; |
| 278 | |
| 279 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!( |
| 280 | secs == 0, |
| 281 | "numeric names are not used if the offset has fractional minutes" |
| 282 | ); |
| 283 | |
| 284 | let _ = writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(&mut f, "{hours:02}"); |
| 285 | if mins rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]ne().0 { |
| 286 | let _ = writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(&mut f, "{mins:02}"); |
| 287 | } |
| 288 | f |
| 289 | } |
| 290 | } |
| 291 | } |
| 292 | |
| 293 | pub fn format_constantrust-analyzer cargo parse-zoneinfo 0.5.0 table/impl#[Format]format_constant().(&self) -> Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String# { |
| 294 | if let Formatrust-analyzer cargo parse-zoneinfo 0.5.0 table/Format#::Constantrust-analyzer cargo parse-zoneinfo 0.5.0 table/Format#Constant#(ref s) = *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().self { |
| 295 | s.clonerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][Clone]clone().() |
| 296 | } else { |
| 297 | panicrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/panic!!("Expected a constant formatting string"); |
| 298 | } |
| 299 | } |
| 300 | } |
| 301 | |
| 302 | /// A builder for `Table` values based on various line definitions. |
| 303 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:)] |
| 304 | pub struct TableBuilderrust-analyzer cargo parse-zoneinfo 0.5.0 table/TableBuilder# { |
| 305 | /// The table that’s being built up. |
| 306 | tablerust-analyzer cargo parse-zoneinfo 0.5.0 table/TableBuilder#table.: Tablerust-analyzer cargo parse-zoneinfo 0.5.0 table/Table#, |
| 307 | |
| 308 | /// If the last line was a zone definition, then this holds its name. |
| 309 | /// `None` otherwise. This is so continuation lines can be added to the |
| 310 | /// same zone as the original zone line. |
| 311 | current_zoneset_namerust-analyzer cargo parse-zoneinfo 0.5.0 table/TableBuilder#current_zoneset_name.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>, |
| 312 | } |
| 313 | |
| 314 | impl Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default# for TableBuilderrust-analyzer cargo parse-zoneinfo 0.5.0 table/TableBuilder# { |
| 315 | fn defaultrust-analyzer cargo parse-zoneinfo 0.5.0 table/impl#[TableBuilder][Default]default().() -> Selfrust-analyzer cargo parse-zoneinfo 0.5.0 table/impl#[TableBuilder][Default] { |
| 316 | Selfrust-analyzer cargo parse-zoneinfo 0.5.0 table/impl#[TableBuilder][Default]::newrust-analyzer cargo parse-zoneinfo 0.5.0 table/impl#[TableBuilder]new().() |
| 317 | } |
| 318 | } |
| 319 | |
| 320 | impl TableBuilderrust-analyzer cargo parse-zoneinfo 0.5.0 table/TableBuilder# { |
| 321 | /// Creates a new builder with an empty table. |
| 322 | pub fn newrust-analyzer cargo parse-zoneinfo 0.5.0 table/impl#[TableBuilder]new().() -> TableBuilderrust-analyzer cargo parse-zoneinfo 0.5.0 table/TableBuilder# { |
| 323 | TableBuilderrust-analyzer cargo parse-zoneinfo 0.5.0 table/TableBuilder# { |
| 324 | tablerust-analyzer cargo parse-zoneinfo 0.5.0 table/TableBuilder#table.: Tablerust-analyzer cargo parse-zoneinfo 0.5.0 table/Table#::defaultrust-analyzer cargo parse-zoneinfo 0.5.0 table/impl#[Table][Default]default().(), |
| 325 | current_zoneset_namerust-analyzer cargo parse-zoneinfo 0.5.0 table/TableBuilder#current_zoneset_name.: Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, |
| 326 | } |
| 327 | } |
| 328 | |
| 329 | pub fn add_linerust-analyzer cargo parse-zoneinfo 0.5.0 table/impl#[TableBuilder]add_line().<'line>(&mut self, line: Linerust-analyzer cargo parse-zoneinfo 0.5.0 line/Line#<'line>) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), Errorrust-analyzer cargo parse-zoneinfo 0.5.0 table/Error#<'line>> { |
| 330 | match line { |
| 331 | Linerust-analyzer cargo parse-zoneinfo 0.5.0 line/Line#::Zonerust-analyzer cargo parse-zoneinfo 0.5.0 line/Line#Zone#(zone) => self.add_zone_linerust-analyzer cargo parse-zoneinfo 0.5.0 table/impl#[TableBuilder]add_zone_line().(zone), |
| 332 | Linerust-analyzer cargo parse-zoneinfo 0.5.0 line/Line#::Continuationrust-analyzer cargo parse-zoneinfo 0.5.0 line/Line#Continuation#(cont) => self.add_continuation_linerust-analyzer cargo parse-zoneinfo 0.5.0 table/impl#[TableBuilder]add_continuation_line().(cont), |
| 333 | Linerust-analyzer cargo parse-zoneinfo 0.5.0 line/Line#::Rulerust-analyzer cargo parse-zoneinfo 0.5.0 line/Line#Rule#(rule) => self.add_rule_linerust-analyzer cargo parse-zoneinfo 0.5.0 table/impl#[TableBuilder]add_rule_line().(rule), |
| 334 | Linerust-analyzer cargo parse-zoneinfo 0.5.0 line/Line#::Linkrust-analyzer cargo parse-zoneinfo 0.5.0 line/Line#Link#(link) => self.add_link_linerust-analyzer cargo parse-zoneinfo 0.5.0 table/impl#[TableBuilder]add_link_line().(link), |
| 335 | Linerust-analyzer cargo parse-zoneinfo 0.5.0 line/Line#::Spacerust-analyzer cargo parse-zoneinfo 0.5.0 line/Line#Space# => Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()), |
| 336 | } |
| 337 | } |
| 338 | |
| 339 | /// Adds a new line describing a zone definition. |
| 340 | /// |
| 341 | /// Returns an error if there’s already a zone with the same name, or the |
| 342 | /// zone refers to a ruleset that hasn’t been defined yet. |
| 343 | pub fn add_zone_linerust-analyzer cargo parse-zoneinfo 0.5.0 table/impl#[TableBuilder]add_zone_line().<'line>( |
| 344 | &mut self, |
| 345 | zone_line: linerust-analyzer cargo parse-zoneinfo 0.5.0 line/::Zonerust-analyzer cargo parse-zoneinfo 0.5.0 line/Zone#<'line>, |
| 346 | ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), Errorrust-analyzer cargo parse-zoneinfo 0.5.0 table/Error#<'line>> { |
| 347 | if let linerust-analyzer cargo parse-zoneinfo 0.5.0 line/::Savingrust-analyzer cargo parse-zoneinfo 0.5.0 line/Saving#::Multiplerust-analyzer cargo parse-zoneinfo 0.5.0 line/Saving#Multiple#(ruleset_name) = zone_line.inforust-analyzer cargo parse-zoneinfo 0.5.0 line/Zone#info..savingrust-analyzer cargo parse-zoneinfo 0.5.0 line/ZoneInfo#saving. { |
| 348 | if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().self.tablerust-analyzer cargo parse-zoneinfo 0.5.0 table/TableBuilder#table..rulesetsrust-analyzer cargo parse-zoneinfo 0.5.0 table/Table#rulesets..contains_keyrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]contains_key().(ruleset_name) { |
| 349 | return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(Errorrust-analyzer cargo parse-zoneinfo 0.5.0 table/Error#::UnknownRulesetrust-analyzer cargo parse-zoneinfo 0.5.0 table/Error#UnknownRuleset#(ruleset_name)); |
| 350 | } |
| 351 | } |
| 352 | |
| 353 | let zoneset = match self.tablerust-analyzer cargo parse-zoneinfo 0.5.0 table/TableBuilder#table..zonesetsrust-analyzer cargo parse-zoneinfo 0.5.0 table/Table#zonesets..entryrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]entry().(zone_line.namerust-analyzer cargo parse-zoneinfo 0.5.0 line/Zone#name..to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().()) { |
| 354 | Entryrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/Entry#::Occupiedrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/Entry#Occupied#(_) => return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(Errorrust-analyzer cargo parse-zoneinfo 0.5.0 table/Error#::DuplicateZonerust-analyzer cargo parse-zoneinfo 0.5.0 table/Error#DuplicateZone#), |
| 355 | Entryrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/Entry#::Vacantrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/Entry#Vacant#(e) => e.insertrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`VacantEntry<'a, K, V, A>`]insert().(Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]new().()), |
| 356 | }; |
| 357 | |
| 358 | zoneset.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(zone_line.inforust-analyzer cargo parse-zoneinfo 0.5.0 line/Zone#info..intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()); |
| 359 | self.current_zoneset_namerust-analyzer cargo parse-zoneinfo 0.5.0 table/TableBuilder#current_zoneset_name. = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(zone_line.namerust-analyzer cargo parse-zoneinfo 0.5.0 line/Zone#name..to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().()); |
| 360 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 361 | } |
| 362 | |
| 363 | /// Adds a new line describing the *continuation* of a zone definition. |
| 364 | /// |
| 365 | /// Returns an error if the builder wasn’t expecting a continuation line |
| 366 | /// (meaning, the previous line wasn’t a zone line) |
| 367 | pub fn add_continuation_linerust-analyzer cargo parse-zoneinfo 0.5.0 table/impl#[TableBuilder]add_continuation_line().<'line>( |
| 368 | &mut self, |
| 369 | continuation_line: linerust-analyzer cargo parse-zoneinfo 0.5.0 line/::ZoneInforust-analyzer cargo parse-zoneinfo 0.5.0 line/ZoneInfo#<'line>, |
| 370 | ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), Errorrust-analyzer cargo parse-zoneinfo 0.5.0 table/Error#<'line>> { |
| 371 | let zoneset = match self.current_zoneset_namerust-analyzer cargo parse-zoneinfo 0.5.0 table/TableBuilder#current_zoneset_name. { |
| 372 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(ref name) => self.tablerust-analyzer cargo parse-zoneinfo 0.5.0 table/TableBuilder#table..zonesetsrust-analyzer cargo parse-zoneinfo 0.5.0 table/Table#zonesets..get_mutrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]get_mut().(name).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(), |
| 373 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(Errorrust-analyzer cargo parse-zoneinfo 0.5.0 table/Error#::SurpriseContinuationLinerust-analyzer cargo parse-zoneinfo 0.5.0 table/Error#SurpriseContinuationLine#), |
| 374 | }; |
| 375 | |
| 376 | zoneset.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(continuation_line.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()); |
| 377 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 378 | } |
| 379 | |
| 380 | /// Adds a new line describing one entry in a ruleset, creating that set |
| 381 | /// if it didn’t exist already. |
| 382 | pub fn add_rule_linerust-analyzer cargo parse-zoneinfo 0.5.0 table/impl#[TableBuilder]add_rule_line().<'line>( |
| 383 | &mut self, |
| 384 | rule_line: linerust-analyzer cargo parse-zoneinfo 0.5.0 line/::Rulerust-analyzer cargo parse-zoneinfo 0.5.0 line/Rule#<'line>, |
| 385 | ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), Errorrust-analyzer cargo parse-zoneinfo 0.5.0 table/Error#<'line>> { |
| 386 | let ruleset = self |
| 387 | .tablerust-analyzer cargo parse-zoneinfo 0.5.0 table/TableBuilder#table. |
| 388 | .rulesetsrust-analyzer cargo parse-zoneinfo 0.5.0 table/Table#rulesets. |
| 389 | .entryrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]entry().(rule_line.namerust-analyzer cargo parse-zoneinfo 0.5.0 line/Rule#name..to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().()) |
| 390 | .or_defaultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`Entry<'a, K, V>`]or_default().(); |
| 391 | |
| 392 | ruleset.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(rule_line.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()); |
| 393 | self.current_zoneset_namerust-analyzer cargo parse-zoneinfo 0.5.0 table/TableBuilder#current_zoneset_name. = Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#; |
| 394 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 395 | } |
| 396 | |
| 397 | /// Adds a new line linking one zone to another. |
| 398 | /// |
| 399 | /// Returns an error if there was already a link with that name. |
| 400 | pub fn add_link_linerust-analyzer cargo parse-zoneinfo 0.5.0 table/impl#[TableBuilder]add_link_line().<'line>( |
| 401 | &mut self, |
| 402 | link_line: linerust-analyzer cargo parse-zoneinfo 0.5.0 line/::Linkrust-analyzer cargo parse-zoneinfo 0.5.0 line/Link#<'line>, |
| 403 | ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), Errorrust-analyzer cargo parse-zoneinfo 0.5.0 table/Error#<'line>> { |
| 404 | match self.tablerust-analyzer cargo parse-zoneinfo 0.5.0 table/TableBuilder#table..linksrust-analyzer cargo parse-zoneinfo 0.5.0 table/Table#links..entryrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]entry().(link_line.newrust-analyzer cargo parse-zoneinfo 0.5.0 line/Link#new..to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().()) { |
| 405 | Entryrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/Entry#::Occupiedrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/Entry#Occupied#(_) => Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(Errorrust-analyzer cargo parse-zoneinfo 0.5.0 table/Error#::DuplicateLinkrust-analyzer cargo parse-zoneinfo 0.5.0 table/Error#DuplicateLink#(link_line.newrust-analyzer cargo parse-zoneinfo 0.5.0 line/Link#new.)), |
| 406 | Entryrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/Entry#::Vacantrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/Entry#Vacant#(e) => { |
| 407 | let _ = e.insertrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`VacantEntry<'a, K, V, A>`]insert().(link_line.existingrust-analyzer cargo parse-zoneinfo 0.5.0 line/Link#existing..to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().()); |
| 408 | self.current_zoneset_namerust-analyzer cargo parse-zoneinfo 0.5.0 table/TableBuilder#current_zoneset_name. = Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#; |
| 409 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 410 | } |
| 411 | } |
| 412 | } |
| 413 | |
| 414 | /// Returns the table after it’s finished being built. |
| 415 | pub fn buildrust-analyzer cargo parse-zoneinfo 0.5.0 table/impl#[TableBuilder]build().(self) -> Tablerust-analyzer cargo parse-zoneinfo 0.5.0 table/Table# { |
| 416 | self.tablerust-analyzer cargo parse-zoneinfo 0.5.0 table/TableBuilder#table. |
| 417 | } |
| 418 | } |
| 419 | |
| 420 | /// Something that can go wrong while constructing a `Table`. |
| 421 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy:, Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:)] |
| 422 | pub enum Errorrust-analyzer cargo parse-zoneinfo 0.5.0 table/Error#<'line> { |
| 423 | /// A continuation line was passed in, but the previous line wasn’t a zone |
| 424 | /// definition line. |
| 425 | SurpriseContinuationLinerust-analyzer cargo parse-zoneinfo 0.5.0 table/Error#SurpriseContinuationLine#, |
| 426 | |
| 427 | /// A zone definition referred to a ruleset that hadn’t been defined. |
| 428 | UnknownRulesetrust-analyzer cargo parse-zoneinfo 0.5.0 table/Error#UnknownRuleset#(&'line str), |
| 429 | |
| 430 | /// A link line was passed in, but there’s already a link with that name. |
| 431 | DuplicateLinkrust-analyzer cargo parse-zoneinfo 0.5.0 table/Error#DuplicateLink#(&'line str), |
| 432 | |
| 433 | /// A zone line was passed in, but there’s already a zone with that name. |
| 434 | DuplicateZonerust-analyzer cargo parse-zoneinfo 0.5.0 table/Error#DuplicateZone#, |
| 435 | } |
| 436 | |
| 437 | impl<'line> fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Displayrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Display# for Errorrust-analyzer cargo parse-zoneinfo 0.5.0 table/Error#<'line> { |
| 438 | fn fmtrust-analyzer cargo parse-zoneinfo 0.5.0 table/impl#[`Error<'line>`][Display]fmt().(&self, f: &mut fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Formatterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Formatter#) -> fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Result# { |
| 439 | match self { |
| 440 | Errorrust-analyzer cargo parse-zoneinfo 0.5.0 table/Error#::SurpriseContinuationLinerust-analyzer cargo parse-zoneinfo 0.5.0 table/Error#SurpriseContinuationLine# => { |
| 441 | writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!( |
| 442 | f, |
| 443 | "continuation line follows line that isn't a zone definition line" |
| 444 | ) |
| 445 | } |
| 446 | Errorrust-analyzer cargo parse-zoneinfo 0.5.0 table/Error#::UnknownRulesetrust-analyzer cargo parse-zoneinfo 0.5.0 table/Error#UnknownRuleset#(_) => { |
| 447 | writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(f, "zone definition refers to a ruleset that isn't defined") |
| 448 | } |
| 449 | Errorrust-analyzer cargo parse-zoneinfo 0.5.0 table/Error#::DuplicateLinkrust-analyzer cargo parse-zoneinfo 0.5.0 table/Error#DuplicateLink#(_) => writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(f, "link line with name that already exists"), |
| 450 | Errorrust-analyzer cargo parse-zoneinfo 0.5.0 table/Error#::DuplicateZonerust-analyzer cargo parse-zoneinfo 0.5.0 table/Error#DuplicateZone# => writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(f, "zone line with name that already exists"), |
| 451 | } |
| 452 | } |
| 453 | } |
| 454 | |
| 455 | impl<'line> stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std error/::Errorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core error/Error# for Errorrust-analyzer cargo parse-zoneinfo 0.5.0 table/Error#<'line> {} |