Debian Codegraph @

src/metadata.rs

raw symbols SCIP
1 //! Database metadata types.
2
3 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/::BTreeMaprust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/map/BTreeMap#;
4 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::timerust-analyzer cargo std https://github.com/rust-lang/rust/library/std time/::{Durationrust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/Duration#, SystemTimerust-analyzer cargo std https://github.com/rust-lang/rust/library/std time/SystemTime#, UNIX_EPOCHrust-analyzer cargo std https://github.com/rust-lang/rust/library/std time/UNIX_EPOCH.};
5
6 use serderust-analyzer cargo serde 1.0.229 crate/::{Deserializerust-analyzer cargo serde_core 1.0.229 de/Deserialize#, Serializerust-analyzer cargo serde_core 1.0.229 ser/Serialize#};
7
8 use craterust-analyzer cargo maxminddb 0.30.0 crate/::errorrust-analyzer cargo maxminddb 0.30.0 error/::MaxMindDbErrorrust-analyzer cargo maxminddb 0.30.0 error/MaxMindDbError#;
9
10 /// Metadata about the MaxMind DB file.
11 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Deserializerust-analyzer cargo serde_derive 1.0.229 Deserialize:, Serializerust-analyzer cargo serde_derive 1.0.229 Serialize:, Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:)]
12 pub struct Metadatarust-analyzer cargo maxminddb 0.30.0 metadata/Metadata# {
13 /// Major version of the binary format (always 2).
14 pub binary_format_major_versionrust-analyzer cargo maxminddb 0.30.0 metadata/Metadata#binary_format_major_version.: u16,
15 /// Minor version of the binary format (always 0).
16 pub binary_format_minor_versionrust-analyzer cargo maxminddb 0.30.0 metadata/Metadata#binary_format_minor_version.: u16,
17 /// Unix timestamp when the database was built.
18 pub build_epochrust-analyzer cargo maxminddb 0.30.0 metadata/Metadata#build_epoch.: u64,
19 /// Database type (e.g., "GeoIP2-City", "GeoLite2-Country").
20 pub database_typerust-analyzer cargo maxminddb 0.30.0 metadata/Metadata#database_type.: Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#,
21 /// Map of language codes to database descriptions.
22 pub descriptionrust-analyzer cargo maxminddb 0.30.0 metadata/Metadata#description.: BTreeMaprust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/map/BTreeMap#<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#>,
23 /// IP version supported (4 or 6).
24 pub ip_versionrust-analyzer cargo maxminddb 0.30.0 metadata/Metadata#ip_version.: u16,
25 /// Languages available in the database.
26 pub languagesrust-analyzer cargo maxminddb 0.30.0 metadata/Metadata#languages.: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>,
27 /// Number of nodes in the search tree.
28 pub node_countrust-analyzer cargo maxminddb 0.30.0 metadata/Metadata#node_count.: u32,
29 /// Size of each record in bits (24, 28, or 32).
30 pub record_sizerust-analyzer cargo maxminddb 0.30.0 metadata/Metadata#record_size.: u16,
31 }
32
33 impl Metadatarust-analyzer cargo maxminddb 0.30.0 metadata/Metadata# {
34 /// Returns the database build time as a `SystemTime`.
35 ///
36 /// This converts the `build_epoch` Unix timestamp to a `SystemTime`.
37 /// If `build_epoch` is too large to represent on this platform, this
38 /// returns an [`InvalidDatabase`](MaxMindDbError::InvalidDatabase) error.
39 ///
40 /// # Example
41 ///
42 /// ```
43 /// use maxminddb::Reader;
44 ///
45 /// let reader = Reader::open_readfile("test-data/test-data/GeoIP2-City-Test.mmdb").unwrap();
46 /// let build_time = reader.metadata().build_time().unwrap();
47 /// println!("Database built: {:?}", build_time);
48 /// ```
49 #[inline]
50 pub fn build_timerust-analyzer cargo maxminddb 0.30.0 metadata/impl#[Metadata]build_time().(&self) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<SystemTimerust-analyzer cargo std https://github.com/rust-lang/rust/library/std time/SystemTime#, MaxMindDbErrorrust-analyzer cargo maxminddb 0.30.0 error/MaxMindDbError#> {
51 UNIX_EPOCHrust-analyzer cargo std https://github.com/rust-lang/rust/library/std time/UNIX_EPOCH.
52 .checked_addrust-analyzer cargo std https://github.com/rust-lang/rust/library/std time/impl#[SystemTime]checked_add().(Durationrust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/Duration#::from_secsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/impl#[Duration]from_secs().(self.build_epochrust-analyzer cargo maxminddb 0.30.0 metadata/Metadata#build_epoch.))
53 .ok_or_elserust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]ok_or_else().(|| {
54 MaxMindDbErrorrust-analyzer cargo maxminddb 0.30.0 error/MaxMindDbError#::invalid_databaserust-analyzer cargo maxminddb 0.30.0 error/impl#[MaxMindDbError]invalid_database().(formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!(
55 "build_epoch - Unix timestamp is too large to represent as SystemTime: {}",
56 self.build_epochrust-analyzer cargo maxminddb 0.30.0 metadata/Metadata#build_epoch.
57 ))
58 })
59 }
60 }