Skip to main content

cranpose_services/
lib.rs

1//! Multiplatform service abstractions used by Cranpose applications.
2
3#![deny(unsafe_code)]
4
5#[cfg(test)]
6use cranpose_core::{location_key, Composition, MemoryApplier};
7
8pub mod http;
9pub mod theme;
10pub mod uri_handler;
11
12pub use http::{
13    default_http_client, local_http_client, map_ordered_concurrent, HttpClient, HttpClientRef,
14    HttpError, HttpFuture,
15};
16pub use theme::{
17    default_system_theme, isSystemInDarkTheme, local_system_theme, ProvideSystemTheme, SystemTheme,
18};
19pub use uri_handler::{
20    default_uri_handler, local_uri_handler, ProvideUriHandler, UriHandler, UriHandlerError,
21    UriHandlerRef,
22};
23
24/// Convenience alias used in unit tests.
25#[cfg(test)]
26pub(crate) type TestComposition = Composition<MemoryApplier>;
27
28/// Build a composition with a simple in-memory applier and run the provided closure once.
29#[cfg(test)]
30pub(crate) fn run_test_composition(build: impl FnMut()) -> TestComposition {
31    let mut composition = Composition::new(MemoryApplier::new());
32    composition
33        .render(location_key(file!(), line!(), column!()), build)
34        .expect("initial render succeeds");
35    composition
36}