b-r-u / osmpbf

A Rust library for reading the OpenStreetMap PBF file format (*.osm.pbf).
Apache License 2.0
122 stars 19 forks source link

Consolidating element and densenode API via a trait #41

Open nyurik opened 1 year ago

nyurik commented 1 year ago

It makes it somewhat combersome at the moment to process node/way/relation vs densenode - requiring complex code paths to handle both cases. I would like to propose a common ElementInfo trait that has just a few changes from the current API:

pub trait ElementInfo<'a> {
    /// Returns the version of this element.
    fn version(&self) -> Option<i32>;

    /// Returns the changeset id.
    fn changeset(&self) -> Option<i64>;

    /// Returns the user id.
    fn uid(&self) -> Option<i32>;

    /// Returns the user name.
    fn user(&self) -> Option<&'a str>;

    /// Returns the time stamp in milliseconds since the epoch.
    fn milli_timestamp(&self) -> Option<i64>;

    /// Returns the visibility status of an element. This is only relevant if the PBF file contains
    /// historical information.
    fn visible(&self) -> Option<bool>;

    /// Returns true if the element was deleted.
    /// This is a convenience function that just returns the inverse of `DenseNodeInfo::visible`.
    fn deleted(&self) -> Option<bool>;
}

Ideally, the same should be done for DenseNode vs Node - if possible to do efficiently (?), the internal details of the dense/nondense implementation shouldn't leak out.