### Trim Start Example Source: https://docs.rs/wreq/5.3.0/wreq/struct.Utf8Bytes.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Demonstrates trimming leading whitespace from a string. ```rust let s = " עברית "; assert!(Some('ע') == s.trim_start().chars().next()); ``` -------------------------------- ### Trim Start Matches Example Source: https://docs.rs/wreq/5.3.0/wreq/struct.Utf8Bytes.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Demonstrates removing a set of characters from the start of a string. ```rust let x: &[_] = &['1', '2']; assert_eq!("12foo1bar12".trim_start_matches(x), "foo1bar12"); ``` -------------------------------- ### Perform a GET Request Source: https://docs.rs/wreq/5.3.0/wreq/index.html Basic example of executing a GET request and retrieving the response body. ```rust let body = wreq::Client::new() .get("https://www.rust-lang.org") .send() .await? .text() .await?; println!("body = {:?}", body); ``` -------------------------------- ### Making a GET request Source: https://docs.rs/wreq/5.3.0/wreq/index.html?search=u32+-%3E+bool Demonstrates how to perform a simple GET request using the wreq client. ```APIDOC ## GET Request ### Description Performs a GET request to a specified URL and retrieves the response body as text. ### Code Example ```rust let body = wreq::Client::new() .get("https://www.rust-lang.org") .send() .await? .text() .await?; ``` ``` -------------------------------- ### Making a GET request Source: https://docs.rs/wreq/5.3.0/wreq/index.html?search=std%3A%3Avec Demonstrates how to perform a simple GET request using the wreq Client. ```APIDOC ## GET Request ### Description Performs a GET request to a specified URL and retrieves the response body as text. ### Code Example ```rust let body = wreq::Client::new() .get("https://www.rust-lang.org") .send() .await? .text() .await?; println!("body = {:?}", body); ``` ``` -------------------------------- ### Trim Start Matches Source: https://docs.rs/wreq/5.3.0/wreq/struct.Utf8Bytes.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Demonstrates removing prefixes that match a pattern. ```rust assert_eq!("11foo1bar11".trim_start_matches('1'), "foo1bar11"); assert_eq!("123foo1bar123".trim_start_matches(char::is_numeric), "foo1bar123"); ``` -------------------------------- ### wreq::Client::get Source: https://docs.rs/wreq/5.3.0/wreq/index.html Initiates a GET request to the specified URL. ```APIDOC ## GET Request ### Description Performs a GET request to the provided URL and returns the response. ### Example ```rust let body = wreq::Client::new() .get("https://www.rust-lang.org") .send() .await? .text() .await?; ``` ``` -------------------------------- ### Configure WebSocket subprotocols Source: https://docs.rs/wreq/5.3.0/wreq/struct.WebSocketRequestBuilder.html Example showing how to set subprotocols for a WebSocket request. ```rust let request = WebSocketRequestBuilder::new(builder) .protocols(["protocol1", "protocol2"]) .build(); ``` -------------------------------- ### Client::request Source: https://docs.rs/wreq/5.3.0/wreq/struct.Client.html Starts building a request with a custom HTTP method and URL. ```APIDOC ## pub fn request(&self, method: Method, url: U) -> RequestBuilder ### Description Start building a `Request` with the `Method` and `Url`. Returns a `RequestBuilder`, which will allow setting headers and the request body before sending. ### Errors This method fails whenever the supplied `Url` cannot be parsed. ``` -------------------------------- ### Method Usage Examples Source: https://docs.rs/wreq/5.3.0/wreq/struct.Method.html Demonstrates basic usage of the Method struct, including creation from bytes, checking idempotency, and string conversion. ```rust use http::Method; assert_eq!(Method::GET, Method::from_bytes(b"GET").unwrap()); assert!(Method::GET.is_idempotent()); assert_eq!(Method::POST.as_str(), "POST"); ``` -------------------------------- ### Check string prefix Source: https://docs.rs/wreq/5.3.0/wreq/struct.Utf8Bytes.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Determines if the string starts with the provided pattern. ```rust let bananas = "bananas"; assert!(bananas.starts_with("bana")); assert!(!bananas.starts_with("nana")); ``` ```rust let bananas = "bananas"; // Note that both of these assert successfully. assert!(bananas.starts_with(&['b', 'a', 'n', 'a'])); assert!(bananas.starts_with(&['a', 'b', 'c', 'd'])); ``` -------------------------------- ### Convert Box to Pin Source: https://docs.rs/wreq/5.3.0/wreq/dns/type.Addrs.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Demonstrates an example of an ambiguous implementation of From for Pin. ```rust struct Foo; // A type defined in this crate. impl From> for Pin { fn from(_: Box<()>) -> Pin { Pin::new(Foo) } } let foo = Box::new(()); let bar = Pin::from(foo); ``` -------------------------------- ### Allocate Box with custom allocator Source: https://docs.rs/wreq/5.3.0/wreq/dns/type.Addrs.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Examples of using new_in and try_new_in with the System allocator. ```rust #![feature(allocator_api)] use std::alloc::System; let five = Box::new_in(5, System); ``` ```rust #![feature(allocator_api)] use std::alloc::System; ``` -------------------------------- ### starts_with

(pat: P) Source: https://docs.rs/wreq/5.3.0/wreq/struct.Utf8Bytes.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Checks if the string starts with the given pattern. ```APIDOC ## starts_with

(pat: P) ### Description Returns true if the given pattern matches a prefix of this string slice. ``` -------------------------------- ### Box initialization with custom allocator Source: https://docs.rs/wreq/5.3.0/wreq/dns/type.Addrs.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Examples of creating boxes with uninitialized or zeroed memory using the allocator API. ```rust let five = Box::try_new_in(5, System)?; ``` ```rust #![feature(allocator_api)] use std::alloc::System; let mut five = Box::::new_uninit_in(System); // Deferred initialization: five.write(5); let five = unsafe { five.assume_init() }; assert_eq!(*five, 5) ``` ```rust #![feature(allocator_api)] use std::alloc::System; let mut five = Box::::try_new_uninit_in(System)?; // Deferred initialization: five.write(5); let five = unsafe { five.assume_init() }; assert_eq!(*five, 5); ``` ```rust #![feature(allocator_api)] use std::alloc::System; let zero = Box::::new_zeroed_in(System); let zero = unsafe { zero.assume_init() }; assert_eq!(*zero, 0) ``` ```rust #![feature(allocator_api)] use std::alloc::System; let zero = Box::::try_new_zeroed_in(System)?; let zero = unsafe { zero.assume_init() }; assert_eq!(*zero, 0); ``` -------------------------------- ### Client::get Source: https://docs.rs/wreq/5.3.0/wreq/struct.Client.html Convenience method to initiate a GET request to a specified URL. ```APIDOC ## pub fn get(&self, url: U) -> RequestBuilder ### Description Convenience method to make a `GET` request to a URL. ### Errors This method fails whenever the supplied `Url` cannot be parsed. ``` -------------------------------- ### Trim Prefix Examples Source: https://docs.rs/wreq/5.3.0/wreq/struct.Utf8Bytes.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Experimental API that returns the string unchanged if the prefix is missing, facilitating method chaining. ```rust #![feature(trim_prefix_suffix)] // Prefix present - removes it assert_eq!("foo:bar".trim_prefix("foo:"), "bar"); assert_eq!("foofoo".trim_prefix("foo"), "foo"); // Prefix absent - returns original string assert_eq!("foo:bar".trim_prefix("bar"), "foo:bar"); // Method chaining example assert_eq!("".trim_prefix('<').trim_suffix('>'), "https://example.com/"); ``` -------------------------------- ### Managing Box memory with into_non_null Source: https://docs.rs/wreq/5.3.0/wreq/dns/type.Addrs.html?search=u32+-%3E+bool Examples demonstrating how to convert a Box to a NonNull pointer and perform cleanup using different methods. ```rust #![feature(box_vec_non_null)] let x = Box::new(String::from("Hello")); let non_null = Box::into_non_null(x); let x = unsafe { Box::from_non_null(non_null) }; ``` ```rust #![feature(box_vec_non_null)] use std::alloc::{dealloc, Layout}; let x = Box::new(String::from("Hello")); let non_null = Box::into_non_null(x); unsafe { non_null.drop_in_place(); dealloc(non_null.as_ptr().cast::(), Layout::new::()); } ``` ```rust #![feature(box_vec_non_null)] let x = Box::new(String::from("Hello")); let non_null = Box::into_non_null(x); unsafe { drop(Box::from_non_null(non_null)); } ``` -------------------------------- ### Initialize EmulationProvider Source: https://docs.rs/wreq/5.3.0/wreq/struct.EmulationProvider.html Demonstrates how to create an EmulationProvider instance using the builder pattern with a default TLS configuration. ```rust use wreq::EmulationProvider; use wreq::TlsConfig; let provider = EmulationProvider::builder() .tls_config(TlsConfig::default()) .build(); ``` -------------------------------- ### Construct Box from Raw Pointer Source: https://docs.rs/wreq/5.3.0/wreq/dns/type.Addrs.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Examples for creating a Box from a raw pointer, either from a previous conversion or manual allocation. ```rust let x = Box::new(5); let ptr = Box::into_raw(x); let x = unsafe { Box::from_raw(ptr) }; ``` ```rust use std::alloc::{alloc, Layout}; unsafe { let ptr = alloc(Layout::new::()) as *mut i32; // In general .write is required to avoid attempting to destruct // the (uninitialized) previous contents of `ptr`, though for this // simple example `*ptr = 5` would have worked as well. ptr.write(5); let x = Box::from_raw(ptr); } ``` -------------------------------- ### Configure Client with Proxy Source: https://docs.rs/wreq/5.3.0/wreq/struct.Proxy.html Demonstrates how to attach different types of proxies to a Client builder. ```rust let client = wreq::Client::builder() .proxy(wreq::Proxy::http("https://my.prox")?) .build()?; ``` ```rust let client = wreq::Client::builder() .proxy(wreq::Proxy::https("https://example.prox:4545")?) .build()?; ``` ```rust let client = wreq::Client::builder() .proxy(wreq::Proxy::all("http://pro.xy")?) .build()?; ``` -------------------------------- ### Clone Box from Reference Source: https://docs.rs/wreq/5.3.0/wreq/dns/type.Addrs.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Example of cloning a Box from a reference using the nightly-only try_clone_from_ref_in API. ```rust let hello: Box = Box::clone_from_ref_in("hello", System); ``` ```rust #![feature(clone_from_ref)] #![feature(allocator_api)] use std::alloc::System; let hello: Box = Box::try_clone_from_ref_in("hello", System)?; ``` -------------------------------- ### Constructing a CertStore with CertStoreBuilder Source: https://docs.rs/wreq/5.3.0/wreq/tls/struct.CertStoreBuilder.html Demonstrates the fluent API for adding certificates and default paths before building the final CertStore. ```rust use wreq::CertStore; let store = CertStore::builder() .add_cert(&der_or_pem_cert) .add_der_cert(&der_cert) .add_pem_cert(&pem_cert) .set_default_paths() .build()?; ``` -------------------------------- ### GET Request Source: https://docs.rs/wreq/5.3.0/wreq/index.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Perform a simple GET request using the wreq client. ```APIDOC ## GET Request ### Description Perform a simple GET request to a specified URL. ### Method GET ### Request Example ```rust let body = wreq::Client::new() .get("https://www.rust-lang.org") .send() .await? .text() .await?; ``` ``` -------------------------------- ### pub fn get(&self, key: K) -> Option<&T> Source: https://docs.rs/wreq/5.3.0/wreq/header/struct.HeaderMap.html?search=std%3A%3Avec Returns a reference to the value associated with the key. ```APIDOC ## pub fn get(&self, key: K) -> Option<&T> ### Description Returns a reference to the value associated with the key. If multiple values exist, the first one is returned. ### Parameters - **key** (K: AsHeaderName) - Required - The header name to look up. ``` -------------------------------- ### Client::new Source: https://docs.rs/wreq/5.3.0/wreq/struct.Client.html Constructs a new Client instance. Note that this method will panic if TLS or resolver initialization fails. ```APIDOC ## pub fn new() -> Client ### Description Constructs a new `Client`. This method panics if a TLS backend cannot be initialized, or the resolver cannot load the system configuration. ``` -------------------------------- ### Convert Box to Raw Pointer Source: https://docs.rs/wreq/5.3.0/wreq/dns/type.Addrs.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Examples for consuming a Box into a raw pointer and performing cleanup. ```rust let x = Box::new(String::from("Hello")); let ptr = Box::into_raw(x); let x = unsafe { Box::from_raw(ptr) }; ``` ```rust use std::alloc::{dealloc, Layout}; use std::ptr; let x = Box::new(String::from("Hello")); let ptr = Box::into_raw(x); unsafe { ptr::drop_in_place(ptr); dealloc(ptr as *mut u8, Layout::new::()); } ``` ```rust let x = Box::new(String::from("Hello")); let ptr = Box::into_raw(x); unsafe { drop(Box::from_raw(ptr)); } ``` -------------------------------- ### Static String Parsing Error Example Source: https://docs.rs/wreq/5.3.0/wreq/header/struct.HeaderName.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Example of a compile-time error message when using an invalid header name with from_static. ```text error: any use of this value will cause an error --> http/src/header/name.rs:1241:13 | 1241 | ([] as [u8; 0])[0]; // Invalid header name | ^^^^^^^^^^^^^^^^^^ | | | index out of bounds: the length is 0 but the index is 0 | inside `http::HeaderName::from_static` at http/src/header/name.rs:1241:13 | inside `INVALID_NAME` at src/main.rs:3:34 | ::: src/main.rs:3:1 | 3 | const INVALID_NAME: HeaderName = HeaderName::from_static("Capitalized"); | ------------------------------------------------------------------------ ``` -------------------------------- ### Panic message example for invalid static header Source: https://docs.rs/wreq/5.3.0/wreq/header/struct.HeaderValue.html?search= Example of the compile-time error message when using an invalid static header value. ```text error: any use of this value will cause an error --> http/src/header/value.rs:67:17 | 67 | ([] as [u8; 0])[0]; // Invalid header value | ^^^^^^^^^^^^^^^^^^ | | | index out of bounds: the length is 0 but the index is 0 | inside `HeaderValue::from_static` at http/src/header/value.rs:67:17 | inside `INVALID_HEADER` at src/main.rs:73:33 | ::: src/main.rs:73:1 | 73 | const INVALID_HEADER: HeaderValue = HeaderValue::from_static("жsome value"); | ---------------------------------------------------------------------------- ``` -------------------------------- ### whole_nanoseconds Source: https://docs.rs/wreq/5.3.0/wreq/cookie/struct.Duration.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Get the number of nanoseconds in the duration. ```APIDOC ## pub const fn whole_nanoseconds(self) -> i128 ### Description Get the number of nanoseconds in the duration. ``` -------------------------------- ### Convert Box to Raw Pointer with Allocator Source: https://docs.rs/wreq/5.3.0/wreq/dns/type.Addrs.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Demonstrates consuming a Box into a raw pointer and allocator, with examples for both automatic and manual cleanup. ```rust #![feature(allocator_api)] use std::alloc::System; let x = Box::new_in(String::from("Hello"), System); let (ptr, alloc) = Box::into_raw_with_allocator(x); let x = unsafe { Box::from_raw_in(ptr, alloc) }; ``` ```rust #![feature(allocator_api)] use std::alloc::{Allocator, Layout, System}; use std::ptr::{self, NonNull}; let x = Box::new_in(String::from("Hello"), System); let (ptr, alloc) = Box::into_raw_with_allocator(x); unsafe { ptr::drop_in_place(ptr); let non_null = NonNull::new_unchecked(ptr); alloc.deallocate(non_null.cast(), Layout::new::()); } ``` -------------------------------- ### get Source: https://docs.rs/wreq/5.3.0/wreq/header/struct.HeaderMap.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Returns a reference to the value associated with the key. ```APIDOC ## pub fn get(&self, key: K) -> Option<&T> ### Description Returns a reference to the value associated with the key. If there are multiple values associated with the key, the first one is returned. ### Parameters - **key** (K: AsHeaderName) - Required - The header name to look up. ``` -------------------------------- ### whole_microseconds Source: https://docs.rs/wreq/5.3.0/wreq/cookie/struct.Duration.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Get the number of whole microseconds in the duration. ```APIDOC ## pub const fn whole_microseconds(self) -> i128 ### Description Get the number of whole microseconds in the duration. ``` -------------------------------- ### Configure Proxy Settings Source: https://docs.rs/wreq/5.3.0/wreq/struct.ClientBuilder.html Demonstrates how to add a proxy to the client using the proxy method with either a Proxy object or a string URL. ```rust use wreq::Client; use wreq::Proxy; let proxy = Proxy::http("http://proxy:8080").unwrap(); let client = Client::builder().proxy(proxy).build().unwrap(); let client = Client::builder().proxy("http://proxy2:8080").build().unwrap(); ``` -------------------------------- ### whole_milliseconds Source: https://docs.rs/wreq/5.3.0/wreq/cookie/struct.Duration.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Get the number of whole milliseconds in the duration. ```APIDOC ## pub const fn whole_milliseconds(self) -> i128 ### Description Get the number of whole milliseconds in the duration. ``` -------------------------------- ### whole_seconds Source: https://docs.rs/wreq/5.3.0/wreq/cookie/struct.Duration.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Get the number of whole seconds in the duration. ```APIDOC ## pub const fn whole_seconds(self) -> i64 ### Description Get the number of whole seconds in the duration. ``` -------------------------------- ### build Source: https://docs.rs/wreq/5.3.0/wreq/tls/struct.CertStoreBuilder.html?search= Constructs the CertStore. ```APIDOC ### pub fn build(self) -> Result Finalizes the builder and constructs the CertStore containing all the added certificates. ``` -------------------------------- ### Get HeaderValue length Source: https://docs.rs/wreq/5.3.0/wreq/header/struct.HeaderValue.html Returns the length of the HeaderValue in bytes. ```rust let val = HeaderValue::from_static("hello"); assert_eq!(val.len(), 5); ``` -------------------------------- ### as_seconds_f32 Source: https://docs.rs/wreq/5.3.0/wreq/cookie/struct.Duration.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Get the number of fractional seconds in the duration as f32. ```APIDOC ## pub fn as_seconds_f32(self) -> f32 ### Description Get the number of fractional seconds in the duration. ``` -------------------------------- ### Part Creation Methods Source: https://docs.rs/wreq/5.3.0/wreq/multipart/struct.Part.html?search=std%3A%3Avec Methods for initializing a Part from various data sources. ```rust pub fn text(value: T) -> Part where T: Into>, ``` ```rust pub fn bytes(value: T) -> Part where T: Into>, ``` ```rust pub fn stream>(value: T) -> Part ``` ```rust pub fn stream_with_length>(value: T, length: u64) -> Part ``` ```rust pub async fn file>(path: T) -> Result ``` -------------------------------- ### as_seconds_f64 Source: https://docs.rs/wreq/5.3.0/wreq/cookie/struct.Duration.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Get the number of fractional seconds in the duration as f64. ```APIDOC ## pub fn as_seconds_f64(self) -> f64 ### Description Get the number of fractional seconds in the duration. ``` -------------------------------- ### ClientBuilder::new Source: https://docs.rs/wreq/5.3.0/wreq/struct.ClientBuilder.html Constructs a new ClientBuilder instance. ```APIDOC ## pub fn new() ### Description Constructs a new `ClientBuilder` instance. This is equivalent to calling `Client::builder()`. ``` -------------------------------- ### Configure Connector Layers Source: https://docs.rs/wreq/5.3.0/wreq/struct.ClientBuilder.html Demonstrates how to add Tower layers to the base connector service, showing the order of execution for timeouts and concurrency limits. ```rust use std::time::Duration; let client = wreq::Client::builder() // resolved to outermost layer, meaning while we are waiting on concurrency limit .connect_timeout(Duration::from_millis(200)) // underneath the concurrency check, so only after concurrency limit lets us through .connector_layer(tower::timeout::TimeoutLayer::new(Duration::from_millis(50))) .connector_layer(tower::limit::concurrency::ConcurrencyLimitLayer::new(2)) .build() .unwrap(); ``` -------------------------------- ### Consuming a Box Source: https://docs.rs/wreq/5.3.0/wreq/dns/type.Addrs.html?search=u32+-%3E+bool Example for extracting the inner value from a box. ```rust #![feature(box_into_inner)] let c = Box::new(5); assert_eq!(Box::into_inner(c), 5); ``` -------------------------------- ### Part Configuration Methods Source: https://docs.rs/wreq/5.3.0/wreq/multipart/struct.Part.html?search=std%3A%3Avec Methods for setting metadata and headers on a Part instance. ```rust pub fn mime_str(self, mime: &str) -> Result ``` ```rust pub fn file_name(self, filename: T) -> Part where T: Into>, ``` ```rust pub fn headers(self, headers: HeaderMap) -> Part ``` -------------------------------- ### subsec_nanoseconds Source: https://docs.rs/wreq/5.3.0/wreq/cookie/struct.Duration.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Get the number of nanoseconds past the number of whole seconds. ```APIDOC ## pub const fn subsec_nanoseconds(self) -> i32 ### Description Get the number of nanoseconds past the number of whole seconds. The returned value will always be in the range -999_999_999..=999_999_999. ``` -------------------------------- ### ClientBuilder::build Source: https://docs.rs/wreq/5.3.0/wreq/struct.ClientBuilder.html Finalizes the configuration and returns a Client instance. ```APIDOC ## pub fn build(self) -> Result ### Description Returns a `Client` that uses the current `ClientBuilder` configuration. This method may fail if TLS backends or system resolvers cannot be initialized. ``` -------------------------------- ### subsec_microseconds Source: https://docs.rs/wreq/5.3.0/wreq/cookie/struct.Duration.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Get the number of microseconds past the number of whole seconds. ```APIDOC ## pub const fn subsec_microseconds(self) -> i32 ### Description Get the number of microseconds past the number of whole seconds. Always in the range -999_999..=999_999. ``` -------------------------------- ### subsec_milliseconds Source: https://docs.rs/wreq/5.3.0/wreq/cookie/struct.Duration.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Get the number of milliseconds past the number of whole seconds. ```APIDOC ## pub const fn subsec_milliseconds(self) -> i16 ### Description Get the number of milliseconds past the number of whole seconds. Always in the range -999..=999. ``` -------------------------------- ### Proxy Creation Methods Source: https://docs.rs/wreq/5.3.0/wreq/struct.Proxy.html Methods to initialize a Proxy instance for different traffic routing scenarios. ```APIDOC ## Proxy::http(proxy_scheme) ### Description Proxy all HTTP traffic to the passed URL. ### Parameters - **proxy_scheme** (IntoProxyScheme) - Required - The URL or scheme of the proxy server. ## Proxy::https(proxy_scheme) ### Description Proxy all HTTPS traffic to the passed URL. ### Parameters - **proxy_scheme** (IntoProxyScheme) - Required - The URL or scheme of the proxy server. ## Proxy::all(proxy_scheme) ### Description Proxy all traffic to the passed URL. ### Parameters - **proxy_scheme** (IntoProxyScheme) - Required - The URL or scheme of the proxy server. ## Proxy::custom(fun) ### Description Provide a custom function to determine what traffic to proxy to where. ### Parameters - **fun** (Fn(&Url) -> Option) - Required - A closure that returns a proxy URL if the request should be proxied. ``` -------------------------------- ### Clone Client Instance Source: https://docs.rs/wreq/5.3.0/wreq/struct.Client.html Shows how to create a new independent instance of a Client that shares the same connection pool as the original. ```rust let client = wreq::Client::new(); let cloned_client = client.cloned(); // Use the cloned client independently ``` -------------------------------- ### EmulationProvider::builder() Source: https://docs.rs/wreq/5.3.0/wreq/struct.EmulationProvider.html Creates a new builder instance to configure and construct an EmulationProvider. ```APIDOC ## pub fn builder() -> EmulationProviderBuilder ### Description Creates a builder for constructing an `EmulationProvider`. Use the builder methods to configure TLS, HTTP/1, HTTP/2, and header settings before calling `.build()`. ### Signature `pub fn builder() -> EmulationProviderBuilder<((), (), (), (), ())>` ``` -------------------------------- ### Checking Result Status Source: https://docs.rs/wreq/5.3.0/wreq/type.Result.html Examples of checking if a Result is Ok or Err. ```rust let x: Result = Ok(-3); assert_eq!(x.is_ok(), true); let x: Result = Err("Some error message"); assert_eq!(x.is_ok(), false); ``` ```rust let x: Result = Ok(-3); assert_eq!(x.is_err(), false); let x: Result = Err("Some error message"); assert_eq!(x.is_err(), true); ``` -------------------------------- ### Flattening Nested Results Source: https://docs.rs/wreq/5.3.0/wreq/type.Result.html Examples of flattening nested Result structures. ```rust let x: Result, u32> = Ok(Ok("hello")); assert_eq!(Ok("hello"), x.flatten()); let x: Result, u32> = Ok(Err(6)); assert_eq!(Err(6), x.flatten()); let x: Result, u32> = Err(6); assert_eq!(Err(6), x.flatten()); ``` ```rust let x: Result, u32>, u32> = Ok(Ok(Ok("hello"))); assert_eq!(Ok(Ok("hello")), x.flatten()); assert_eq!(Ok("hello"), x.flatten().flatten()); ``` -------------------------------- ### Create NoProxy from environment Source: https://docs.rs/wreq/5.3.0/wreq/struct.NoProxy.html Initializes a NoProxy configuration by reading from environment variables. ```rust pub fn from_env() -> Option ``` -------------------------------- ### Cloning Result Contents Source: https://docs.rs/wreq/5.3.0/wreq/type.Result.html Examples of using .cloned() on Result references. ```rust let val = 12; let x: Result<&i32, i32> = Ok(&val); assert_eq!(x, Ok(&12)); let cloned = x.cloned(); assert_eq!(cloned, Ok(12)); ``` ```rust let mut val = 12; let x: Result<&mut i32, i32> = Ok(&mut val); assert_eq!(x, Ok(&mut 12)); let cloned = x.cloned(); assert_eq!(cloned, Ok(12)); ``` -------------------------------- ### Create a new Form with text fields Source: https://docs.rs/wreq/5.3.0/wreq/multipart/struct.Form.html?search=u32+-%3E+bool Demonstrates initializing a new Form and adding text fields using the text method. ```rust let form = wreq::multipart::Form::new() .text("username", "seanmonstar") .text("password", "secret"); ``` -------------------------------- ### Copying Result Contents Source: https://docs.rs/wreq/5.3.0/wreq/type.Result.html Examples of using .copied() on Result references. ```rust let val = 12; let x: Result<&i32, i32> = Ok(&val); assert_eq!(x, Ok(&12)); let copied = x.copied(); assert_eq!(copied, Ok(12)); ``` ```rust let mut val = 12; let x: Result<&mut i32, i32> = Ok(&mut val); assert_eq!(x, Ok(&mut 12)); let copied = x.copied(); assert_eq!(copied, Ok(12)); ``` -------------------------------- ### Get References with as_ref Source: https://docs.rs/wreq/5.3.0/wreq/type.Result.html?search=u32+-%3E+bool Converts a Result reference into a Result containing references. ```rust let x: Result = Ok(2); assert_eq!(x.as_ref(), Ok(&2)); let x: Result = Err("Error"); assert_eq!(x.as_ref(), Err(&"Error")); ``` -------------------------------- ### Basic HeaderMap Usage Source: https://docs.rs/wreq/5.3.0/wreq/header/struct.HeaderMap.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Demonstrates standard operations including inserting, checking for existence, accessing, and removing headers. ```rust let mut headers = HeaderMap::new(); headers.insert(HOST, "example.com".parse().unwrap()); headers.insert(CONTENT_LENGTH, "123".parse().unwrap()); assert!(headers.contains_key(HOST)); assert!(!headers.contains_key(LOCATION)); assert_eq!(headers[HOST], "example.com"); headers.remove(HOST); assert!(!headers.contains_key(HOST)); ``` -------------------------------- ### Initialize a SOCKS proxy Source: https://docs.rs/wreq/5.3.0/wreq/struct.Proxy.html Requires the 'socks' feature to be enabled to use a SOCKS5 proxy. ```rust let proxy = wreq::Proxy::http("socks5://192.168.1.1:9000")?; ``` -------------------------------- ### Client Methods Source: https://docs.rs/wreq/5.3.0/wreq/struct.Client.html?search=u32+-%3E+bool Methods available on the wreq::Client struct for initiating requests and configuring the client. ```APIDOC ## Client::new() Constructs a new Client. Panics if TLS backend or resolver initialization fails. ## Client::builder() Creates a ClientBuilder configured for WebSocket connections. ## Client::get(url) Initiates a GET request to the specified URL. ## Client::post(url) Initiates a POST request to the specified URL. ## Client::put(url) Initiates a PUT request to the specified URL. ## Client::patch(url) Initiates a PATCH request to the specified URL. ## Client::delete(url) Initiates a DELETE request to the specified URL. ## Client::head(url) Initiates a HEAD request to the specified URL. ## Client::request(method, url) Starts building a custom Request with the specified Method and URL. ## Client::websocket(url) Upgrades a request for a WebSocket handshake (requires 'websocket' feature). ## Client::execute(request) Executes a pre-built Request. ``` -------------------------------- ### Dst::new Source: https://docs.rs/wreq/5.3.0/wreq/struct.Dst.html Creates a new Dst instance based on the provided URI, HTTP connect flag, network scheme, and optional HTTP version. ```APIDOC ## fn new(uri: &mut Uri, is_http_connect: bool, network: NetworkScheme, version: Option) -> Result ### Description Creates a new `Dst` instance. This method initializes a new `Dst` instance based on the provided URI, HTTP connect flag, network scheme, and HTTP version. ### Parameters - **uri** (&mut Uri) - Required - A mutable reference to the URI of the request. - **is_http_connect** (bool) - Required - A boolean indicating whether the request is an HTTP CONNECT request. - **network** (NetworkScheme) - Required - The network scheme to be used for the request. - **version** (Option) - Required - An optional HTTP version for the request. ### Returns - **Result** - A Result containing the constructed Dst or an Error if the URI is not absolute. ``` -------------------------------- ### Build a Cookie from a base Source: https://docs.rs/wreq/5.3.0/wreq/cookie/struct.RawCookie.html?search= Create a CookieBuilder starting from a base cookie or value. ```rust use cookie::Cookie; // Use `(K, V)` as the base, setting a name and value. let b1 = Cookie::build(("name", "value")).path("/"); assert_eq!(b1.inner().name_value(), ("name", "value")); assert_eq!(b1.inner().path(), Some("/")); // Use `&str` as the base, setting a name and empty value. let b2 = Cookie::build(("name")); assert_eq!(b2.inner().name_value(), ("name", "")); // Use `CookieBuilder` as the base, inheriting all properties. let b3 = Cookie::build(b1); assert_eq!(b3.inner().name_value(), ("name", "value")); assert_eq!(b3.inner().path(), Some("/")); ``` -------------------------------- ### Configure Client Emulation Source: https://docs.rs/wreq/5.3.0/wreq/struct.ClientBuilder.html Sets the HTTP context emulation for the client. Must be called before any other HTTP1/HTTP2/TLS fine-tuning as it overwrites existing configurations. ```rust use wreq::{Client, Emulation}; use wreq_util::Emulation; let client = Client::builder() .emulation(Emulation::Firefox128) .build() .unwrap(); ``` -------------------------------- ### Request::new Source: https://docs.rs/wreq/5.3.0/wreq/struct.Request.html Constructs a new Request instance. ```APIDOC ## pub fn new(method: Method, url: Url) -> Self ### Description Constructs a new request with the specified HTTP method and URL. ### Parameters - **method** (Method) - Required - The HTTP method for the request. - **url** (Url) - Required - The target URL for the request. ``` -------------------------------- ### Transposing Result and Option Source: https://docs.rs/wreq/5.3.0/wreq/type.Result.html Example of transposing a Result of an Option into an Option of a Result. ```rust #[derive(Debug, Eq, PartialEq)] struct SomeErr; let x: Result, SomeErr> = Ok(Some(5)); let y: Option> = Some(Ok(5)); assert_eq!(x.transpose(), y); ``` -------------------------------- ### CertStore Methods Source: https://docs.rs/wreq/5.3.0/wreq/tls/struct.CertStore.html?search=std%3A%3Avec Methods available for creating and initializing a CertStore instance. ```APIDOC ## pub fn builder() -> CertStoreBuilder Creates a new CertStoreBuilder. ## pub fn from_identity(identity: Identity) -> CertStore Creates a new CertStore from an Identity. ## pub fn from_certs<'c, I>(certs: I) -> Result Creates a new CertStore from a collection of DER/PEM-encoded certificates. ## pub fn from_der_certs<'c, C>(certs: C) -> Result Creates a new CertStore from a collection of DER-encoded certificates. ## pub fn from_pem_certs<'c, C>(certs: C) -> Result Creates a new CertStore from a collection of PEM-encoded certificates. ## pub fn from_pem_stack(certs: C) -> Result Creates a new CertStore from a PEM-encoded certificate stack. ## pub fn from_pem_file

(path: P) -> Result Creates a new CertStore from a PEM-encoded certificate file. ``` -------------------------------- ### Strip Circumfix Examples Source: https://docs.rs/wreq/5.3.0/wreq/struct.Utf8Bytes.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Experimental API to remove both a prefix and a suffix exactly once. ```rust #![feature(strip_circumfix)] assert_eq!("bar:hello:foo".strip_circumfix("bar:", ":foo"), Some("hello")); assert_eq!("bar:foo".strip_circumfix("foo", "foo"), None); assert_eq!("foo:bar;".strip_circumfix("foo:", ';'), Some("bar")); ``` -------------------------------- ### wreq::multipart::Form::new Source: https://docs.rs/wreq/5.3.0/wreq/multipart/struct.Form.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Creates a new async Form instance without any initial content. ```APIDOC ## pub fn new() -> Form ### Description Creates a new async Form without any content. ### Signature `pub fn new() -> Form` ``` -------------------------------- ### Strip Suffix Examples Source: https://docs.rs/wreq/5.3.0/wreq/struct.Utf8Bytes.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Removes a suffix exactly once if present, returning an Option. ```rust assert_eq!("bar:foo".strip_suffix(":foo"), Some("bar")); assert_eq!("bar:foo".strip_suffix("bar"), None); assert_eq!("foofoo".strip_suffix("foo"), Some("foo")); ``` -------------------------------- ### fn into(self) -> Option> Source: https://docs.rs/wreq/5.3.0/wreq/tls/trait.IntoCertStore.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Converts the implementing type into an optional Cow containing a CertStore. ```APIDOC ### Method fn into(self) -> Option> ### Description Converts the given value into an optional `Cow` containing a `CertStore`. ### Returns - **Option>** - An optional Cow containing the certificate store. ``` -------------------------------- ### Strip Prefix Examples Source: https://docs.rs/wreq/5.3.0/wreq/struct.Utf8Bytes.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Removes a prefix exactly once if present, returning an Option. ```rust assert_eq!("foo:bar".strip_prefix("foo:"), Some("bar")); assert_eq!("foo:bar".strip_prefix("bar"), None); assert_eq!("foofoo".strip_prefix("foo"), Some("foo")); ``` -------------------------------- ### Creating an Empty HeaderMap Source: https://docs.rs/wreq/5.3.0/wreq/header/struct.HeaderMap.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Shows how to initialize a new HeaderMap without pre-allocated capacity. ```rust let map = HeaderMap::new(); assert!(map.is_empty()); assert_eq!(0, map.capacity()); ``` -------------------------------- ### Taking a value from a Box Source: https://docs.rs/wreq/5.3.0/wreq/dns/type.Addrs.html?search=u32+-%3E+bool Example for consuming a box while retaining the allocation for reuse. ```rust #![feature(box_take)] let c = Box::new(5); // take the value out of the box let (value, uninit) = Box::take(c); assert_eq!(value, 5); // reuse the box for a second value let c = Box::write(uninit, 6); assert_eq!(*c, 6); ``` -------------------------------- ### Proxy Configuration Methods Source: https://docs.rs/wreq/5.3.0/wreq/struct.Proxy.html Methods to configure authentication and headers for an existing Proxy instance. ```APIDOC ## Proxy::basic_auth(username, password) ### Description Set the Proxy-Authorization header using Basic auth. ## Proxy::custom_http_auth(header_value) ### Description Set the Proxy-Authorization header to a specified value. ## Proxy::custom_http_headers(headers) ### Description Set custom HTTP headers to be used with the proxy. ### Parameters - **headers** (HeaderMap) - Required - A HeaderMap containing the custom headers to be set. ## Proxy::no_proxy(no_proxy) ### Description Adds a No Proxy exclusion list to this Proxy. ### Parameters - **no_proxy** (Option) - Required - The exclusion list configuration. ``` -------------------------------- ### Checking Expiration Type Source: https://docs.rs/wreq/5.3.0/wreq/cookie/enum.Expiration.html Examples for checking if an Expiration is a DateTime or a Session variant. ```rust use cookie::Expiration; use time::OffsetDateTime; let expires = Expiration::from(None); assert!(!expires.is_datetime()); let expires = Expiration::from(OffsetDateTime::now_utc()); assert!(expires.is_datetime()); ``` ```rust use cookie::Expiration; use time::OffsetDateTime; let expires = Expiration::from(None); assert!(expires.is_session()); let expires = Expiration::from(OffsetDateTime::now_utc()); assert!(!expires.is_session()); ``` -------------------------------- ### Get Raw Pointer Source: https://docs.rs/wreq/5.3.0/wreq/struct.Utf8Bytes.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Retrieves a raw pointer to the first byte of the string slice. ```rust let s = "Hello"; let ptr = s.as_ptr(); ``` -------------------------------- ### Implement EmulationProviderFactory Source: https://docs.rs/wreq/5.3.0/wreq/trait.EmulationProviderFactory.html Demonstrates implementing the trait for a custom struct. ```rust use wreq::{EmulationProviderFactory, EmulationProvider}; struct MyEmulationProvider; impl EmulationProviderFactory for MyEmulationProvider { fn emulation(self) -> EmulationProvider { EmulationProvider::default() } } let provider = MyEmulationProvider.emulation(); ``` -------------------------------- ### Get URL Port Source: https://docs.rs/wreq/5.3.0/wreq/struct.Url.html?search= Returns the explicit port number, excluding default ports. ```rust use url::Url; let url = Url::parse("https://example.com")?; assert_eq!(url.port(), None); let url = Url::parse("https://example.com:443/")?; assert_eq!(url.port(), None); let url = Url::parse("ssh://example.com:22")?; assert_eq!(url.port(), Some(22)); ``` -------------------------------- ### Get URL Scheme Source: https://docs.rs/wreq/5.3.0/wreq/struct.Url.html?search= Returns the lower-cased scheme of the URL without the colon delimiter. ```rust use url::Url; let url = Url::parse("file:///tmp/foo")?; assert_eq!(url.scheme(), "file"); ``` -------------------------------- ### Import HeaderName constant Source: https://docs.rs/wreq/5.3.0/wreq/header/struct.HeaderName.html Shows how to import a predefined header name constant. ```rust use http::header::CONTENT_LENGTH; ``` -------------------------------- ### Retrieve URI scheme as string Source: https://docs.rs/wreq/5.3.0/wreq/struct.Dst.html Gets the scheme component of a URI as a string slice. ```rust let uri: Uri = "http://example.org/hello/world".parse().unwrap(); assert_eq!(uri.scheme_str(), Some("http")); ``` -------------------------------- ### entry() Source: https://docs.rs/wreq/5.3.0/wreq/header/struct.HeaderMap.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Gets the given key’s corresponding entry in the map for in-place manipulation. ```APIDOC ## pub fn entry(&mut self, key: K) -> Entry<'_, T> ### Description Gets the given key’s corresponding entry in the map for in-place manipulation. ### Parameters - **key** (K) - The key to look up. ### Panics This method panics if capacity exceeds max HeaderMap capacity. ``` -------------------------------- ### Trim ASCII whitespace from start Source: https://docs.rs/wreq/5.3.0/wreq/struct.Utf8Bytes.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Removes leading ASCII whitespace, excluding U+000B. ```rust assert_eq!(" \t \u{3000}hello world\n".trim_ascii_start(), "\u{3000}hello world\n"); assert_eq!(" ".trim_ascii_start(), ""); assert_eq!("".trim_ascii_start(), ""); ``` -------------------------------- ### Try Clone Box from Reference Source: https://docs.rs/wreq/5.3.0/wreq/dns/type.Addrs.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Attempts to allocate memory and clone the source, returning an AllocError if allocation fails. ```rust #![feature(clone_from_ref)] #![feature(allocator_api)] let hello: Box = Box::try_clone_from_ref("hello")?; ``` -------------------------------- ### Create NoProxy from string Source: https://docs.rs/wreq/5.3.0/wreq/struct.NoProxy.html Initializes a NoProxy configuration from a comma-separated string of bypass rules. ```rust pub fn from_string(no_proxy_list: &str) -> Option ``` -------------------------------- ### Find match indices with match_indices Source: https://docs.rs/wreq/5.3.0/wreq/struct.Utf8Bytes.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Returns an iterator over disjoint matches and their starting indices. ```rust let v: Vec<_> = "abcXXXabcYYYabc".match_indices("abc").collect(); assert_eq!(v, [(0, "abc"), (6, "abc"), (12, "abc")]); let v: Vec<_> = "1abcabc2".match_indices("abc").collect(); assert_eq!(v, [(1, "abc"), (4, "abc")]); let v: Vec<_> = "ababa".match_indices("aba").collect(); assert_eq!(v, [(0, "aba")]); // only the first `aba` ```