gosub_sonar/lib.rs
1//! Browser-agnostic HTTP/HTTPS fetching library.
2//!
3//! Two APIs are available depending on how much control you need:
4//!
5//! - [`simple_get`] — one-shot GET, no setup required.
6//! - [`Fetcher`] — priority-scheduled fetcher with request coalescing,
7//! per-origin concurrency limits, and fan-out to multiple subscribers.
8//!
9//! For the full scheduler, implement [`FetcherContext`] to receive lifecycle callbacks,
10//! or use [`NullContext`] if you don't need any:
11//!
12//! ```no_run
13//! use std::sync::Arc;
14//! use gosub_sonar::{FetchRequest, Fetcher, FetcherConfig, NullContext};
15//! use http::Method;
16//! use tokio_util::sync::CancellationToken;
17//! use url::Url;
18//!
19//! # async fn example() -> anyhow::Result<()> {
20//! let fetcher = Arc::new(Fetcher::new(FetcherConfig::default(), Arc::new(NullContext))?);
21//!
22//! let shutdown = CancellationToken::new();
23//! tokio::spawn({
24//! let f = fetcher.clone();
25//! let cancel = shutdown.clone();
26//! async move { f.run(cancel).await }
27//! });
28//!
29//! let req = FetchRequest::builder(Method::GET, Url::parse("https://example.org")?).build();
30//! let result = fetcher.fetch(req).await;
31//! # Ok(())
32//! # }
33//! ```
34//!
35//! The most common types are re-exported at the crate root; the full API remains
36//! available under [`net`].
37//!
38//! # Examples
39//!
40//! Runnable examples are in the `examples/` directory:
41//!
42//! - `simple_fetch` — one-shot GET using [`simple_get`]
43//! - `fetcher` — minimal [`Fetcher`] setup with a no-op context
44//! - `fetcher_harness` — self-contained harness covering concurrency, coalescing, priority, cancellation, and errors
45
46#![forbid(unsafe_code)]
47#![deny(clippy::todo)]
48#![deny(clippy::unimplemented)]
49#![deny(clippy::dbg_macro)]
50#![cfg_attr(
51 not(test),
52 deny(clippy::unwrap_used, clippy::expect_used, clippy::panic)
53)]
54
55pub mod http;
56pub mod net;
57pub mod types;
58
59pub use net::fetcher::{Fetcher, FetcherConfig};
60pub use net::fetcher_context::{FetcherContext, NullContext};
61pub use net::null_emitter::NullEmitter;
62pub use net::observer::NetObserver;
63pub use net::request_ref::RequestReference;
64pub use net::shared_body::SharedBody;
65pub use net::simple::{simple_get, sync_fetch, sync_get};
66pub use net::types::{
67 FetchHandle, FetchKeyData, FetchRequest, FetchRequestBuilder, FetchResult, FetchResultMeta,
68 Initiator, NetError, Priority, RequestBody, ResourceKind,
69};
70pub use types::{PeekBuf, RequestId};