mln_rs/lib.rs
1//! A MapLibre map renderer written in Rust.
2//!
3//! The root holds the thread-safe handles of `mln_runtime`: a [`Runtime`]
4//! and its [`Map`]s, whose commands run on the runtime's thread and report
5//! through a [`Completion`], and the [`RenderSession`]s that draw them.
6//!
7//! The library crates of <https://github.com/maplibre/mln-rs> are re-exported
8//! here under their crate names: `mln_rs::mln_engine`, `mln_rs::mln_style`,
9//! `mln_rs::mln_builtins`, and so on. They are published as the `mln-rs-*`
10//! packages, which only exist for this crate. The tile worker codec's
11//! encoding (`mln_wire`) is internal to mln-rs: [`layer`] re-exports only
12//! what a layer type's buckets implement, the `Wire` trait and its derive,
13//! with its `Reader` and `Writer`.
14//!
15//! The library logs through `tracing` and installs no subscriber: install
16//! one, such as `tracing-subscriber`'s, to read its events. An event's target
17//! is `<crate>::<event>`, where the event says what logged it, as the C API's
18//! log events do: `mln_style::parse_style`, `mln_engine::database`,
19//! `mln_vulkan::render`. The offline database's errors carry their SQLite or
20//! I/O error code in a `code` field. An event is a static message plus named
21//! fields, such as `source_id` or `error`, for a subscriber to filter and
22//! format. wgpu and naga log through `log`; a
23//! subscriber reads their records with `tracing-log`'s `LogTracer`.
24//!
25//! A crate that adds a custom layer writes a [`mln_plugin::LayerPlugin`] and
26//! registers it in the [`RegistryBuilder`](mln_engine::RegistryBuilder) of the
27//! map's [`Registry`](mln_engine::Registry) via
28//! [`RegistryBuilder::add_layer_plugin`](mln_engine::RegistryBuilder::add_layer_plugin)
29//! ([`Runtime::with_registry`]). Lower-level engine-internal layer and source
30//! contracts live in [`layer`] and [`source`].
31//!
32//! GeoJSON is the `geojson` crate's and feature geometry is `geo_types`'.
33//! Both crates are re-exported.
34//!
35//! Each backend is a feature, which re-exports its crate: `metal`
36//! (`mln_mtl`), `vulkan` (`mln_vulkan`), `d3d12` (`mln_d3d12`), `gl`
37//! (`mln_gl`) and `webgpu` (`mln_webgpu`). All but `webgpu` are on by
38//! default; natively, wgpu renders through the same APIs as the others, so
39//! turn it on to share a wgpu device or surface with the map.
40//!
41//! The `sqlite` feature, on by default, gives a native runtime its cache
42//! database: the ambient cache, offline regions and `mbtiles://` sources.
43//! An app links one `sqlite3`, so with this feature the app's own `rusqlite`,
44//! if it has one, must accept a version that mln-rs accepts too. An app that
45//! doesn't need the cache database can turn the feature off and keep the
46//! backends it uses:
47//!
48//! ```sh
49//! cargo add mln-rs --no-default-features --features metal,vulkan,d3d12,gl
50//! ```
51//!
52//! Without it, [`RuntimeOptions::cache_path`],
53//! [`Runtime::run_cache_database_operation`],
54//! [`Runtime::set_maximum_ambient_cache_size`] and [`Runtime::offline`]'s
55//! calls fail with `ErrorKind::Unsupported`, as they do in the browser build.
56
57#![warn(clippy::unwrap_used, clippy::expect_used, clippy::panic)]
58#![cfg_attr(not(test), warn(clippy::unreachable, clippy::print_stdout, clippy::print_stderr))]
59
60pub use geo_types;
61pub use geojson;
62pub use glam;
63pub mod layer;
64pub use mln_builtins;
65/// Empty except on Windows.
66#[cfg(feature = "d3d12")]
67pub use mln_d3d12;
68pub use mln_engine;
69pub use mln_gfx;
70#[cfg(feature = "gl")]
71pub use mln_gl;
72/// Empty except on Apple platforms.
73#[cfg(feature = "metal")]
74pub use mln_mtl;
75pub use mln_plugin;
76// Every runtime type is at the root, so the root can't miss one that a
77// root type's methods take or return.
78pub use mln_runtime::{self, *};
79pub use mln_style;
80/// Empty on Apple platforms and in the browser build.
81#[cfg(feature = "vulkan")]
82pub use mln_vulkan;
83#[cfg(feature = "webgpu")]
84pub use mln_webgpu;
85pub mod source;