timvw-rust-runtime 0.3.0

Runtime for clients generated by openapi-generator-timvw-rust: a tower-based HTTP client with a reqwest-like request builder
Documentation
#![cfg_attr(
    all(feature = "reqwest", feature = "retry", feature = "tracing"),
    doc = include_str!("../README.md")
)]
#![cfg_attr(
    not(all(feature = "reqwest", feature = "retry", feature = "tracing")),
    doc = "Runtime for Rust clients generated by [openapi-generator-timvw-rust](https://github.com/timvw/openapi-generator-timvw-rust): a tower-based HTTP client. See the README for the guide."
)]
#![cfg_attr(docsrs, feature(doc_cfg))]
// On WebAssembly the shared pieces of bodies and uploads (`Arc`s) hold streams that are not `Send`: there is one
// thread, and an `Arc` keeps the code the same as natively.
#![cfg_attr(target_family = "wasm", allow(clippy::arc_with_non_send_sync))]

mod body;
mod client;
#[cfg(all(feature = "fs", not(target_family = "wasm")))]
mod download;
mod error;
mod local_service;
mod maybe;
pub mod multipart;
pub mod provider;
mod request;
mod request_options;
#[cfg(feature = "reqwest")]
mod reqwest_service;
mod response;
#[cfg(feature = "retry")]
pub mod retry;
pub mod sse;
#[cfg(feature = "time")]
mod timer;
#[cfg(feature = "tracing")]
pub mod trace;
mod upload;

pub use body::Body;
pub use client::{Client, HttpService};
pub use error::Error;
pub use local_service::LocalBoxCloneService;
pub use maybe::{MaybeSend, MaybeSync};
pub use provider::ProviderLayer;
pub use request::RequestBuilder;
pub use request_options::RequestOptions;
#[cfg(feature = "reqwest")]
pub use reqwest_service::ReqwestService;
pub use response::Response;
pub use upload::Upload;

pub use http;
pub use http::{header, HeaderMap, Method, StatusCode};
/// Credentials of a generated `Configuration` are [`SecretString`]s: their `Debug` is redacted, their memory is
/// zeroed when dropped, and [`ExposeSecret::expose_secret`] reads them.
pub use secrecy;
pub use secrecy::{ExposeSecret, SecretString};
pub use tower;

/// The error type services and layers return: any error that can cross threads.
pub type BoxError = Box<dyn std::error::Error + Send + Sync>;

/// Natively, what the crate hands out stays `Send` (and `Sync` where it was): [`MaybeSend`] relaxes bounds on
/// WebAssembly only.
#[cfg(all(test, not(target_family = "wasm")))]
mod send_tests {
    use super::*;

    fn send_sync<T: Send + Sync>() {}
    fn send<T: Send>(_: &T) {}

    #[test]
    fn natively_clients_bodies_and_futures_are_send() {
        send_sync::<Client>();
        send_sync::<HttpService>();
        send_sync::<Body>();
        send_sync::<Response>();
        send_sync::<RequestBuilder>();
        send_sync::<Upload>();
        send_sync::<multipart::Form>();
        send_sync::<ProviderLayer>();
        let request = Client::default().request(Method::GET, "https://example.com/");
        send(&request.send());
        let response = Response::from(http::Response::new(Body::empty()));
        let events = Response::from(http::Response::new(Body::empty())).events();
        send(&events);
        send(&events.json::<serde_json::Value>());
        send(&response.bytes_stream());
        #[cfg(feature = "time")]
        send(
            &sse::Events::from_bytes(futures_util::stream::empty::<Result<&'static [u8], Error>>())
                .idle_timeout(std::time::Duration::from_secs(1)),
        );
    }
}