1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
//! # twilight-http //! //! HTTP support for the twilight ecosystem. //! //! ## Features //! //! ### Deserialization //! //! `twilight-http` supports [`serde_json`] and [`simd-json`] for deserializing //! responses. These features are mutually exclusive. `serde_json` is enabled by //! default. //! //! #### `serde_json` //! //! [`serde_json`] is the inverse of `simd-json` and will use the `serde_json` //! crate to deserialize responses. //! //! This is enabled by default. //! //! #### `simd-json` //! //! The `simd-json` feature enables [`simd-json`] support to use simd features of //! the modern cpus to deserialize responses faster. It is not enabled by //! default. //! //! To use this feature you need to also add these lines to //! `<project root>/.cargo/config`: //! //! ```toml //! [build] //! rustflags = ["-C", "target-cpu=native"] //! ``` //! //! You can also set the environment variable //! `RUSTFLAGS="-C target-cpu=native"`. If you enable both `serde_json` and //! `simd-json` at the same time, then `simd-json` will be used. //! //! To enable `simd-json`, do something like this in your `Cargo.toml`: //! //! ```toml //! [dependencies] //! twilight-http = { branch = "trunk", default-features = false, features = ["native", "simd-json"], git = "https://github.com/twilight-rs/twilight" } //! ``` //! //! ### TLS //! //! `twilight-http` has features to enable [`reqwest`]'s TLS features. These //! features are mutually exclusive. `native` is enabled by default. //! //! #### `native` //! //! The `native` feature enables [`reqwest`]'s `default-tls` //! feature, which is mostly equivalent to using [`native-tls`]. //! //! This is enabled by default. //! //! #### `rustls` //! //! The `rustls` feature enables [`reqwest`]'s `rustls` feature, which uses //! [`rustls`] as the TLS backend. //! //! To enable `rustls`, do something like this in your `Cargo.toml`: //! //! ```toml //! [dependencies] //! twilight-http = { branch = "trunk", default-features = false, features = ["rustls", "serde_json"], git = "https://github.com/twilight-rs/twilight" } //! ``` //! //! [`native-tls`]: https://crates.io/crates/native-tls //! [`reqwest`]: https://crates.io/crates/reqwest //! [`rustls`]: https://crates.io/crates/rustls //! [`serde_json`]: https://crates.io/crates/serde_json //! [`simd-json`]: https://crates.io/crates/simd-json #![deny( clippy::all, clippy::pedantic, future_incompatible, nonstandard_style, rust_2018_idioms, unused, warnings )] #![allow( clippy::module_name_repetitions, clippy::pub_enum_variant_names, clippy::must_use_candidate, clippy::missing_errors_doc )] pub mod api_error; pub mod client; pub mod error; pub mod ratelimiting; pub mod request; pub mod routing; pub use crate::{ client::Client, error::{Error, Result}, }; #[cfg(all(feature = "serde_json", not(feature = "simd-json")))] use serde_json::Result as JsonResult; #[cfg(feature = "simd-json")] use simd_json::Result as JsonResult; pub(crate) fn json_from_slice<'a, T: serde::de::Deserialize<'a>>(s: &'a mut [u8]) -> JsonResult<T> { #[cfg(all(feature = "serde_json", not(feature = "simd-json")))] return serde_json::from_slice(s); #[cfg(feature = "simd-json")] return simd_json::from_slice(s); } #[cfg(all(feature = "serde_json", not(feature = "simd-json")))] pub(crate) use serde_json::to_vec as json_to_vec; #[cfg(feature = "simd-json")] pub(crate) use simd_json::to_vec as json_to_vec; #[cfg(not(any(feature = "native", feature = "rustls")))] compile_error!("Either the `native` or `rustls` feature must be enabled.");