Skip to main content

Crate sumo_types

Crate sumo_types 

Source
Expand description

Reads SUMO files into well-typed Rust structs.

Each SUMO file format is its own Cargo feature, generated from that format’s XSD; see FEATURE_SCHEMAS in build.rs for the current list. Two are implemented:

FeatureFormatPublic API
net (default).net.xml (netconvert output)domain, read_network
routes.rou.xml (traffic demand)routes

Those are written as plain code spans, not intra-doc links, throughout this crate-level comment: it can’t be #[cfg]-gated (a //! comment isn’t attached to a single item), so it is rendered under every feature combination, and a link to a feature-gated item is a broken link in every build that doesn’t enable it. Everything named here is reachable from the module list below under the features that provide it.

net’s API sits at the crate root (sumo_types::domain::Network, sumo_types::read_network) because it was this crate’s first, only format; that path is kept stable even though net’s own files live under src/net/ internally — a module’s file location and its public path are independent in Rust, and lib.rs re-exports net’s public items at the root on purpose. routes, added later, didn’t inherit that spot: it’s namespaced at sumo_types::routes instead, both to avoid colliding with net’s type names (both formats have their own Route-shaped concepts: net::domain doesn’t, but a third format might) and so the module a type is imported from tells you which SUMO format it belongs to.

Every format has 2 layers of types and a conversion step between them. For net:

.net.xml --(xsd-parser, at build time)--> schema --(schema_mapper)--> domain
  • schema (layer 1, generated at build time from the XSDs in xsd/) — an almost literal mirror of the SUMO schema, with no domain semantics. Private: it is an implementation detail, and keeping it so is what keeps xsd-parser-types out of this crate’s public API (see the module’s own comment in lib.rs). Shared by every enabled format (see FEATURE_SCHEMAS in build.rs), so schema::NetType and schema::RoutesType both live there when both features are on.
  • schema_mapper converts layer 1 into layer 2, interpreting SUMO’s text-encoded positions, shapes, boundaries, and enumerations along the way. For example, schema::LaneType::shape is a raw String ("0.00,0.00 100.00,0.00"); net’s schema_mapper turns it into a domain::Shape (a Vec<domain::Point>).
  • domain (layer 2) — hand-written types independent of SUMO/XSD. This is what consumers build on: domain for net, routes::domain for routes. The two are unrelated Rust types even where SUMO’s concepts overlap (a route’s edges and a network’s edges are both just ids, domain::EdgeId vs. routes::domain::EdgeRef) — routes doesn’t require net to be enabled, so it can’t borrow its types.

read_network runs the whole pipeline for net, so consumers only ever have to deal with layer 2 (see its own doc comment in net/reader.rs for a runnable example) — marked ignore here rather than no_run because this doc comment has no #[cfg(feature = "net")] to gate it (crate-level //! docs can’t be attached to a single item), so it has to compile under every feature combination, including routes alone:

ⓘ
let network = sumo_types::read_network(std::path::Path::new("city.net.xml"))?;
println!("{} edges", network.edges.len());

Re-exports§

pub use uom;

Modules§

routes
routes format: reads .rou.xml. Namespaced here (rather than re-exported at the crate root like net) — see the crate docs. routes format: reads .rou.xml (traffic demand: routes, vehicle types, vehicles). Own namespace at sumo_types::routes — see the crate docs for why, unlike net, it isn’t flattened to the crate root.

Structs§

Network
Complete model of a SUMO network (.net.xml), already converted to the project’s own types and decoupled from the original XSD schema.

Functions§

read_network
Reads and deserializes the .net.xml file at path into a Network.
read_network_from
Same as read_network, for callers that already have the .net.xml bytes in hand (an in-memory buffer, a decompressed stream, …) rather than a file on disk.