Skip to main content

osm_rail_graph/
lib.rs

1//! Build deterministic, profile-specific railway routing graphs.
2//!
3//! The crate reads the extraction GeoPackage described in the project
4//! documentation and writes a routing-oriented GeoPackage. Most users interact
5//! with it through the `osm-rail-graph` CLI. Library users can call
6//! [`build_graph`] with [`BuildOptions`].
7
8#![warn(missing_docs)]
9
10mod builder;
11mod geometry;
12mod model;
13mod output;
14mod profile;
15
16pub use builder::{BuildOptions, BuildReport, build_graph};
17pub use profile::Profile;
18
19use thiserror::Error;
20
21/// An error produced while reading input or building a graph.
22#[derive(Debug, Error)]
23pub enum Error {
24    /// The input GeoPackage or a build option is invalid.
25    #[error("input error: {0}")]
26    Input(String),
27    /// The requested output path already exists.
28    #[error("output already exists: {0}")]
29    OutputExists(String),
30    /// SQLite could not read or write a database.
31    #[error("database error: {0}")]
32    Database(#[from] rusqlite::Error),
33    /// A JSON attribute could not be decoded or encoded.
34    #[error("JSON error: {0}")]
35    Json(#[from] serde_json::Error),
36    /// A filesystem operation failed.
37    #[error("I/O error: {0}")]
38    Io(#[from] std::io::Error),
39    /// The graph-building worker pool could not be created.
40    #[error("failed to create graph build worker pool: {0}")]
41    ThreadPool(#[from] rayon::ThreadPoolBuildError),
42}
43
44/// The result type used by this crate.
45pub type Result<T> = std::result::Result<T, Error>;