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:
| Feature | Format | Public 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)--> domainschema(layer 1, generated at build time from the XSDs inxsd/) — an almost literal mirror of the SUMO schema, with no domain semantics. Private: it is an implementation detail, and keeping it so is what keepsxsd-parser-typesout of this crate’s public API (see the module’s own comment inlib.rs). Shared by every enabled format (seeFEATURE_SCHEMASinbuild.rs), soschema::NetTypeandschema::RoutesTypeboth live there when both features are on.schema_mapperconverts layer 1 into layer 2, interpreting SUMO’s text-encoded positions, shapes, boundaries, and enumerations along the way. For example,schema::LaneType::shapeis a rawString("0.00,0.00 100.00,0.00");net’sschema_mapperturns it into adomain::Shape(aVec<domain::Point>).domain(layer 2) — hand-written types independent of SUMO/XSD. This is what consumers build on:domainfornet,routes::domainforroutes. 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::EdgeIdvs.routes::domain::EdgeRef) —routesdoesn’t requirenetto 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
routesformat: reads.rou.xml. Namespaced here (rather than re-exported at the crate root likenet) — see the crate docs.routesformat: reads.rou.xml(traffic demand: routes, vehicle types, vehicles). Own namespace atsumo_types::routes— see the crate docs for why, unlikenet, 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.xmlfile atpathinto aNetwork. - read_
network_ from - Same as
read_network, for callers that already have the.net.xmlbytes in hand (an in-memory buffer, a decompressed stream, …) rather than a file on disk.