Skip to main content

trillium_client/
lib.rs

1#![cfg_attr(docsrs, feature(doc_cfg))]
2#![forbid(unsafe_code)]
3#![deny(
4    clippy::dbg_macro,
5    missing_copy_implementations,
6    rustdoc::missing_crate_level_docs,
7    missing_debug_implementations,
8    missing_docs,
9    nonstandard_style,
10    unused_qualifications
11)]
12
13//! trillium client is a http client that uses the same `conn` approach as
14//! [`trillium`](https://trillium.rs) but which can be used
15//! independently for any http client application.
16//!
17//! ## Connector
18//!
19//! [`trillium_client::Client`](Client) is built with a [`Connector`]. Each runtime crate
20//! ([`trillium_smol`](https://docs.trillium.rs/trillium_smol),
21//! [`trillium_tokio`](https://docs.trillium.rs/trillium_tokio),
22//! [`trillium_async_std`](https://docs.trillium.rs/trillium_async_std)) offers
23//! a Connector implementation, which can optionally be combined with a
24//! tls crate such as
25//! [`trillium_rustls`](https://docs.trillium.rs/trillium_rustls) or
26//! [`trillium_native_tls`](https://docs.trillium.rs/trillium_native_tls).
27//!
28//! See the documentation for [`Client`] and [`Conn`] for further usage
29//! examples.
30
31#[cfg(test)]
32#[doc = include_str!("../README.md")]
33mod readme {}
34mod client;
35mod conn;
36mod h3;
37mod into_url;
38mod pool;
39mod response_body;
40mod util;
41#[cfg(feature = "websockets")]
42pub mod websocket;
43
44pub use client::Client;
45#[cfg(any(feature = "serde_json", feature = "sonic-rs"))]
46pub use conn::ClientSerdeError;
47pub use conn::{Conn, USER_AGENT, UnexpectedStatusError};
48pub use into_url::IntoUrl;
49// open an issue if you have a reason for pool to be public
50pub(crate) use pool::Pool;
51pub use response_body::ResponseBody;
52pub use trillium_http::{
53    Body, Error, HeaderName, HeaderValue, HeaderValues, Headers, KnownHeaderName, Method, Result,
54    Status, Version,
55};
56pub use trillium_server_common::{
57    ArcedConnector, ArcedQuicClientConfig, Connector, QuicClientConfig, Url,
58};
59#[cfg(feature = "websockets")]
60pub use trillium_websockets::{WebSocketConfig, WebSocketConn, async_tungstenite, tungstenite};
61#[cfg(feature = "websockets")]
62pub use websocket::WebSocketUpgradeError;
63
64#[cfg(all(feature = "serde_json", feature = "sonic-rs"))]
65compile_error!("cargo features \"serde_json\" and \"sonic-rs\" are mutually exclusive");
66
67#[cfg(feature = "serde_json")]
68#[cfg_attr(docsrs, doc(cfg(feature = "serde_json")))]
69pub use serde_json::{Value, json};
70#[cfg(feature = "sonic-rs")]
71#[cfg_attr(docsrs, doc(cfg(feature = "sonic-rs")))]
72pub use sonic_rs::{Value, json};
73
74/// constructs a new [`Client`] -- alias for [`Client::new`]
75pub fn client(connector: impl Connector) -> Client {
76    Client::new(connector)
77}