### Send a GET Request and Process Response Source: https://docs.rs/minreq This example demonstrates sending a simple GET request to a URL and then processing the response. It shows how to access the response body, status code, and reason phrase. The `?` operator is used for error handling, as the server might return invalid UTF-8 or encounter download issues. ```rust let response = minreq::get("http://example.com").send()?; assert!(response.as_str()?.contains("")); assert_eq!(200, response.status_code); assert_eq!("OK", response.reason_phrase); ``` -------------------------------- ### Send a GET Request with Custom Headers Source: https://docs.rs/minreq You can add custom headers to your requests using the `with_header()` method. This example sets the `Accept` header to `text/html` before sending the GET request. ```rust let response = minreq::get("http://example.com") .with_header("Accept", "text/html") .send()?; ``` -------------------------------- ### GET Request Function Source: https://docs.rs/minreq/2.14.1/minreq/fn.get.html Provides documentation for the `get` function, which is an alias for `Request::new` with the HTTP method set to GET. ```APIDOC ## GET Request ### Description Alias for `Request::new` with `method` set to `Method::Get`. This function is used to perform an HTTP GET request to a specified URL. ### Method GET ### Endpoint N/A (This is a function call, not a direct HTTP endpoint) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```rust use minreq::get; let response = get("https://www.rust-lang.org"); ``` ### Response #### Success Response (200) Returns a `Request` object that can be further manipulated or executed. #### Response Example ```json { "status": 200, "headers": { ... }, "body": "..." } ``` ``` -------------------------------- ### Send HTTP GET Request and Get Response Body as String Source: https://docs.rs/minreq/2.14.1/minreq/struct.Response.html Use this to send an HTTP GET request to a URL and retrieve the response body as a string. Ensure the response body is valid UTF-8. ```rust let response = minreq::get("http://example.com").send()?; println!("{}", response.as_str()?); ``` -------------------------------- ### HTTP Request Methods Source: https://docs.rs/minreq/2.14.1/minreq/index.html The minreq library provides helper functions for standard HTTP methods including GET, POST, PUT, DELETE, HEAD, OPTIONS, PATCH, TRACE, and CONNECT. ```APIDOC ## HTTP Methods ### Description Helper functions to initiate HTTP requests using specific methods. ### Methods - minreq::get(url) - minreq::post(url) - minreq::put(url) - minreq::delete(url) - minreq::head(url) - minreq::options(url) - minreq::patch(url) - minreq::trace(url) - minreq::connect(url) ### Request Example let response = minreq::get("http://example.com").send()?; ``` -------------------------------- ### Send HTTP GET Request and Get Response Body as Bytes Source: https://docs.rs/minreq/2.14.1/minreq/struct.Response.html Use this to send an HTTP GET request and access the raw bytes of the response body. This is useful for non-textual data. ```rust let response = minreq::get(url).send()?; println!("{:?}", response.as_bytes()); ``` -------------------------------- ### Send HTTP GET Request and Consume Response Body into Bytes Source: https://docs.rs/minreq/2.14.1/minreq/struct.Response.html Use this to send an HTTP GET request and take ownership of the response body as a Vec. Note that this consumes the Response object. ```rust let response = minreq::get(url).send()?; println!("{:?}", response.into_bytes()); // This would error, as into_bytes consumes the Response: // let x = response.status_code; ``` -------------------------------- ### Send HTTP GET Request and Parse JSON Response Body Source: https://docs.rs/minreq/2.14.1/minreq/struct.Response.html Use this to send an HTTP GET request to a JSON resource and parse the response body into a specified struct using Serde. Explicitly declare the return type if the compiler cannot infer it. ```rust use serde_json::Value; // Value could be any type that implements Deserialize! let user = minreq::get(url_to_json_resource).send()?.json::()?; println!("User name is '{}'", user["name"]); ``` -------------------------------- ### Enable Optional Features in Cargo.toml Source: https://docs.rs/minreq To enable optional functionality for the minreq crate, specify the desired features in your Cargo.toml file. For example, to enable punycode support for non-ASCII domains, add the 'punycode' feature. ```toml [dependencies] minreq = { version = "2.14.1", features = ["punycode"] } ``` -------------------------------- ### Create a PUT Request Source: https://docs.rs/minreq/2.14.1/minreq/fn.put.html Use this function as an alias for Request::new when the HTTP method is set to Method::Put. No additional setup is required. ```Rust pub fn put>(url: T) -> Request ``` -------------------------------- ### Send a POST Request with a Body Source: https://docs.rs/minreq To send data in the body of a POST request, use the `with_body()` method before calling `send()`. This example sends the string "Foobar" as the request body. ```rust let response = minreq::post("http://example.com") .with_body("Foobar") .send()?; ``` -------------------------------- ### Convert String to Byte Slice in Rust Source: https://docs.rs/minreq/2.14.1/minreq/type.URL.html Illustrates how to get a byte slice representation of a String's contents using `as_bytes`. This is the inverse of `from_utf8`. ```rust let s = String::from("hello"); assert_eq!(&[104, 101, 108, 108, 111], s.as_bytes()); ``` -------------------------------- ### Concatenate Strings Source: https://docs.rs/minreq/2.14.1/minreq/type.URL.html Examples of concatenating Strings and string slices using the + operator. ```rust let a = String::from("hello"); let b = String::from(" world"); let c = a + &b; // `a` is moved and can no longer be used here. ``` ```rust let a = String::from("hello"); let b = String::from(" world"); let c = a.clone() + &b; // `a` is still valid here. ``` ```rust let a = "hello"; let b = " world"; let c = a.to_string() + b; ``` -------------------------------- ### Display Implementation for Method Enum Source: https://docs.rs/minreq/2.14.1/minreq/enum.Method.html Formats the `Method` enum variants into their corresponding HTTP request method strings (e.g., `Method::Get` becomes "GET"). ```rust fn fmt(&self, f: &mut Formatter<'_>) -> Result ``` -------------------------------- ### minreq get function signature Source: https://docs.rs/minreq/2.14.1/minreq/fn.get.html This is the function signature for `minreq::get`. It's an alias for `Request::new` with the method set to `Method::Get`. ```rust pub fn get>(url: T) -> Request ``` -------------------------------- ### Configure Proxy Server Source: https://docs.rs/minreq Sets up a proxy server for a request using `with_proxy()`. Requires the `proxy` feature to be enabled. Supports `host:port` and `user:password@proxy:host` formats for HTTP CONNECT proxies. ```rust #[cfg(feature = "proxy")] { let proxy = minreq::Proxy::new("localhost:8080")?; let response = minreq::post("http://example.com") .with_proxy(proxy) .send()?; println!("{}", response.as_str()?); } ``` -------------------------------- ### POST Request Initialization Source: https://docs.rs/minreq/2.14.1/minreq/fn.post.html Documentation for the post function which initializes a new HTTP POST request. ```APIDOC ## POST (Function: post) ### Description Initializes a new HTTP POST request. This is an alias for Request::new with the method set to Method::Post. ### Method POST ### Parameters #### Path Parameters - **url** (T: Into) - Required - The destination URL for the request. ``` -------------------------------- ### Using Proxy Servers Source: https://docs.rs/minreq Details how to configure and use an HTTP CONNECT proxy for outgoing requests. ```APIDOC ## Using Proxy Servers ### Description Configure an HTTP CONNECT proxy for making requests. The proxy can be specified with or without authentication. ### Method POST (Example shown, applies to other methods) ### Endpoint http://example.com ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```rust #[cfg(feature = "proxy")] { // Proxy format: "host:port" or "user:password@host:port" let proxy = minreq::Proxy::new("localhost:8080")?; let response = minreq::post("http://example.com") .with_proxy(proxy) .send()?; println!("{}", response.as_str()?); } ``` ### Response #### Success Response (200) - **body** (String) - The response body from the target server. #### Response Example ```json { "body": "Response content from the proxied server" } ``` ``` -------------------------------- ### Create a POST request with minreq Source: https://docs.rs/minreq/2.14.1/minreq/fn.post.html Use this function to initialize a request with the POST method. ```rust pub fn post>(url: T) -> Request ``` -------------------------------- ### Initialize New String Source: https://docs.rs/minreq/2.14.1/minreq/type.URL.html Creates an empty String without initial allocation. ```rust let s = String::new(); ``` -------------------------------- ### Request Creation Source: https://docs.rs/minreq/2.14.1/minreq/struct.Request.html Demonstrates how to create a new HTTP request with a specified method and URL. ```APIDOC ## POST /api/users ### Description Creates a new HTTP Request. This is only the request’s data, it is not sent yet. For sending the request, see `send`. ### Method POST ### Endpoint /api/users ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```rust let request = minreq::post("http://example.com"); ``` ### Response #### Success Response (200) None #### Response Example None ``` -------------------------------- ### Proxy Configuration Source: https://docs.rs/minreq/2.14.1/minreq/struct.Proxy.html Details on the Proxy struct and its constructor. ```APIDOC ## Struct Proxy ### Description Proxy configuration. Only HTTP CONNECT proxies are supported (no SOCKS or HTTPS). When credentials are provided, the Basic authentication type is used for Proxy-Authorization. ### `pub fn new>(proxy: S) -> Result` Creates a new Proxy configuration. Supported proxy format is: ``` [http://][user[:password]@]host[:port] ``` The default port is 8080, to be changed to 1080 in minreq 3.0. #### Example ```rust let proxy = minreq::Proxy::new("user:password@localhost:1080").unwrap(); let request = minreq::post("http://example.com").with_proxy(proxy); ``` ``` -------------------------------- ### Get String Length in Bytes Source: https://docs.rs/minreq/2.14.1/minreq/type.URL.html Returns the number of bytes in a String. Note that this may not correspond to the number of characters or graphemes. ```rust let a = String::from("foo"); assert_eq!(a.len(), 3); let fancy_f = String::from("ƒoo"); assert_eq!(fancy_f.len(), 4); assert_eq!(fancy_f.chars().count(), 3); ``` -------------------------------- ### Create OPTIONS Request Source: https://docs.rs/minreq/2.14.1/minreq/fn.options.html Alias for Request::new with `method` set to Method::Options. Use this to create an OPTIONS request for a given URL. ```rust pub fn options>(url: T) -> Request ``` -------------------------------- ### Create a new Proxy configuration Source: https://docs.rs/minreq/2.14.1/minreq/struct.Proxy.html Use this function to create a new Proxy configuration. Supported proxy format is: [http://][user[:password]@]host[:port]. The default port is 8080, to be changed to 1080 in minreq 3.0. ```rust let proxy = minreq::Proxy::new("user:password@localhost:1080").unwrap(); let request = minreq::post("http://example.com").with_proxy(proxy); ``` -------------------------------- ### Proxy Configuration Source: https://docs.rs/minreq/2.14.1/minreq/index.html Configure HTTP CONNECT proxies for requests. ```APIDOC ## Proxy Configuration ### Description Use an HTTP CONNECT proxy for requests by creating a Proxy instance. ### Usage - **Proxy::new(host:port)**: Creates a new proxy configuration. - **with_proxy(proxy)**: Applies the proxy to the request. ### Request Example let proxy = minreq::Proxy::new("localhost:8080")?; let response = minreq::post("http://example.com") .with_proxy(proxy) .send()?; ``` -------------------------------- ### Reserve Capacity for a String in Rust Source: https://docs.rs/minreq/2.14.1/minreq/type.URL.html Demonstrates how to reserve capacity for a String and shrink it to a specific size. Ensure the capacity is at least the requested size after reserving and shrinking. ```rust let mut s = String::from("foo"); s.reserve(100); assert!(s.capacity() >= 100); s.shrink_to(10); assert!(s.capacity() >= 10); s.shrink_to(0); assert!(s.capacity() >= 3); ``` -------------------------------- ### CloneToUninit (Nightly Experimental) Source: https://docs.rs/minreq/2.14.1/minreq/enum.Method.html An experimental nightly-only API for performing copy-assignment from `self` to an uninitialized destination pointer. ```rust unsafe fn clone_to_uninit(&self, dest: *mut u8) ``` -------------------------------- ### impl Default for String Source: https://docs.rs/minreq/2.14.1/minreq/type.URL.html Creates an empty String. ```APIDOC ## impl Default for String ### Description Implements the `Default` trait, providing a way to create an empty `String` using `String::default()`. ### Method `default` ### Endpoint N/A (Associated function for String type) ### Request Body None ### Request Example ```rust let empty_string: String = String::default(); assert!(empty_string.is_empty()); ``` ### Response #### Success Response (200) - **String** - An empty `String`. #### Response Example ```rust let default_string: String = /* result of String::default() */; ``` ``` -------------------------------- ### Initialize String with Capacity Source: https://docs.rs/minreq/2.14.1/minreq/type.URL.html Creates an empty String with a pre-allocated buffer to reduce reallocations. ```rust let mut s = String::with_capacity(10); // The String contains no chars, even though it has capacity for more assert_eq!(s.len(), 0); // These are all done without reallocating... let cap = s.capacity(); for _ in 0..10 { s.push('a'); } assert_eq!(s.capacity(), cap); // ...but this may make the string reallocate s.push('a'); ``` -------------------------------- ### Proxy Implementations Source: https://docs.rs/minreq/2.14.1/minreq/struct.Proxy.html Details on the implementations for the Proxy struct. ```APIDOC ### impl Clone for Proxy #### `fn clone(&self) -> Proxy` Returns a duplicate of the value. #### `fn clone_from(&mut self, source: &Self)` Performs copy-assignment from `source`. ### impl Debug for Proxy #### `fn fmt(&self, f: &mut Formatter<'_>) -> Result` Formats the value using the given formatter. ### impl PartialEq for Proxy #### `fn eq(&self, other: &Proxy) -> bool` Tests for `self` and `other` values to be equal, and is used by `==`. #### `fn ne(&self, other: &Rhs) -> bool` Tests for `!=`. ### impl Eq for Proxy ### impl StructuralPartialEq for Proxy ``` -------------------------------- ### TRACE Request Initialization Source: https://docs.rs/minreq/2.14.1/minreq/fn.trace.html The trace function is an alias for Request::new with the method set to Method::Trace. ```APIDOC ## TRACE /url ### Description Initializes a new HTTP TRACE request for the specified URL. ### Method TRACE ### Parameters #### Path Parameters - **url** (T: Into) - Required - The destination URL for the request. ### Response - **Request** (Object) - Returns a Request object configured with the TRACE method. ``` -------------------------------- ### from_raw_parts Source: https://docs.rs/minreq/2.14.1/minreq/type.URL.html Creates a new String from a pointer, a length, and a capacity. ```APIDOC ## pub unsafe fn from_raw_parts(buf: *mut u8, length: usize, capacity: usize) -> String ### Description Creates a new String from a pointer, a length and a capacity. This is highly unsafe and requires strict adherence to memory invariants. ### Method Function Call ### Parameters - **buf** (*mut u8) - Required - Pointer to the buffer. - **length** (usize) - Required - Length of the string. - **capacity** (usize) - Required - Capacity of the buffer. ### Response - **String** (String) - The reconstructed String. ``` -------------------------------- ### Extrema and Aggregation Source: https://docs.rs/minreq/2.14.1/minreq/struct.ResponseLazy.html Methods for finding minimum/maximum values or calculating sums and products. ```APIDOC ## max / min ### Description Returns the maximum or minimum element of an iterator. ## max_by / min_by ### Description Returns the extrema based on a custom comparison function. ## sum / product ### Description Calculates the sum or product of all elements in the iterator. ``` -------------------------------- ### Create a PATCH request with minreq Source: https://docs.rs/minreq/2.14.1/minreq/fn.patch.html Use this function to initialize a request with the PATCH method. It accepts any type that implements Into. ```rust pub fn patch>(url: T) -> Request ``` -------------------------------- ### fn from Source: https://docs.rs/minreq/2.14.1/minreq/type.URL.html Converts various types into a String. ```APIDOC ## fn from ### Description Converts various types such as &String, &mut str, &str, Box, Cow<'a, str>, and char into a String. ### Parameters #### Request Body - **s** (Various) - Required - The input value to convert into a String. ``` -------------------------------- ### Setting Request Timeouts Source: https://docs.rs/minreq Explains how to configure timeouts for HTTP requests, either per-request or globally via environment variables. ```APIDOC ## Setting Request Timeouts ### Description Configure a timeout for HTTP requests to prevent them from running indefinitely. Timeouts can be set per-request using `with_timeout` or globally using the `MINREQ_TIMEOUT` environment variable. Per-request settings override environment variables. ### Method POST (Example shown, applies to other methods) ### Endpoint http://example.com ### Parameters #### Query Parameters None #### Request Body None ### Request Example (Per-request timeout) ```rust let response = minreq::post("http://example.com") .with_timeout(10) // Timeout in seconds .send()?; ``` ### Request Example (Environment variable) Set the `MINREQ_TIMEOUT` environment variable before running the application. ```bash $ MINREQ_TIMEOUT=8 ./your_program ``` ### Response #### Success Response (200) - **status** (String) - Indicates success. #### Response Example ```json { "status": "Request completed within timeout" } ``` ``` -------------------------------- ### minreq::connect Source: https://docs.rs/minreq/2.14.1/minreq/fn.connect.html Creates a new Request with the method set to Method::Connect. ```APIDOC ## connect ### Description Alias for `Request::new` with `method` set to `Method::Connect`. ### Function Signature ```rust pub fn connect>(url: T) -> Request ``` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```json { "example": "No direct request body example for connect function, as it's a constructor." } ``` ### Response #### Success Response (200) Returns a `Request` object configured for the CONNECT method. #### Response Example ```json { "example": "Request object configured for CONNECT method." } ``` ``` -------------------------------- ### Request::options Source: https://docs.rs/minreq/2.14.1/minreq/fn.options.html Creates a new request with the HTTP method set to OPTIONS. ```APIDOC ## Request::options ### Description Alias for `Request::new` with `method` set to `Method::Options`. ### Method POST ### Endpoint N/A (This is a function signature, not a REST endpoint) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```rust use minreq::Method; let url = "http://example.com"; let request = minreq::options(url); ``` ### Response #### Success Response (200) Returns a `Request` object configured for the OPTIONS method. #### Response Example ```rust // Example of a Request object (structure not fully detailed in source) // let request = Request { ... }; ``` ``` -------------------------------- ### Proxy Configuration Source: https://docs.rs/minreq/2.14.1/minreq/struct.Request.html Method for setting a proxy for the request. ```APIDOC ## Request Configuration - Proxy ### Description Sets the proxy to be used for the HTTP request. ### Method Chained method call on `Request` object. ### Endpoint N/A (Configuration) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```rust // Assuming Proxy struct is defined elsewhere // let proxy = Proxy::new("http://proxy.example.com:8080"); // let request = minreq::get("http://example.com").with_proxy(proxy); ``` ### Response #### Success Response (200) None #### Response Example None ``` -------------------------------- ### Create a POST Request Source: https://docs.rs/minreq/2.14.1/minreq/struct.Request.html Use this to create a new HTTP POST request. You will typically call `send` or `send_lazy` on the returned request object. ```rust let request = minreq::post("http://example.com"); ``` -------------------------------- ### String Implementations Source: https://docs.rs/minreq/2.14.1/minreq/type.URL.html Details on various methods available for the String type, as implemented and used by minreq. ```APIDOC ## Implementations for String ### `String::new()` #### Description Creates a new empty `String`. This operation does not allocate any initial buffer. #### Examples ```rust let s = String::new(); ``` ### `String::with_capacity(capacity: usize)` #### Description Creates a new empty `String` with at least the specified capacity. This can help prevent excessive reallocations when appending data. #### Examples ```rust let mut s = String::with_capacity(10); assert_eq!(s.len(), 0); for _ in 0..10 { s.push('a'); } assert_eq!(s.capacity(), 10); s.push('a'); // This may cause a reallocation ``` ### `String::try_with_capacity(capacity: usize)` #### Description Creates a new empty `String` with at least the specified capacity. This is a nightly-only experimental API. #### Errors Returns `Err` if the capacity exceeds `isize::MAX` bytes, or if the memory allocator reports failure. ### `String::from_utf8(vec: Vec)` #### Description Converts a vector of bytes to a `String`. It checks if the bytes are valid UTF-8. #### Errors Returns `Err` if the slice is not UTF-8, including a description of the error. The original vector is also returned. #### Examples ```rust let sparkle_heart = vec![240, 159, 146, 150]; let sparkle_heart = String::from_utf8(sparkle_heart).unwrap(); assert_eq!("💖", sparkle_heart); let invalid_bytes = vec![0, 159, 146, 150]; assert!(String::from_utf8(invalid_bytes).is_err()); ``` ### `String::from_utf8_lossy(v: &[u8])` #### Description Converts a slice of bytes to a string, replacing any invalid UTF-8 sequences with the replacement character (``). Returns a `Cow<'a, str>`. #### Examples ```rust let valid_utf8 = b"hello"; let s = String::from_utf8_lossy(valid_utf8); assert_eq!(s, "hello"); let invalid_utf8 = &[0, 159, 146, 150]; let s = String::from_utf8_lossy(invalid_utf8); assert_eq!(s, ""); ``` ``` -------------------------------- ### Configuring Request Timeouts Source: https://docs.rs/minreq/2.14.1/minreq/index.html Set request timeouts using the with_timeout method or the MINREQ_TIMEOUT environment variable. Per-request settings override environment variables. ```rust let response = minreq::post("http://example.com") .with_timeout(10) .send()?; ``` ```rust minreq::get("/").with_timeout(8).send(); ``` ```bash $ MINREQ_TIMEOUT=8 ./foo ``` ```rust std::env::set_var("MINREQ_TIMEOUT", "8"); ``` -------------------------------- ### Handling Response Headers Source: https://docs.rs/minreq Demonstrates how to access and read response headers. Header names are case-insensitive and are provided in lowercase. ```APIDOC ## Accessing Response Headers ### Description Retrieve and inspect headers from an HTTP response. The `headers` field is a `HashMap` where keys are lowercase header names. ### Method GET ### Endpoint N/A (This is a client-side operation on a received response) ### Request Example ```rust let response = minreq::get("http://example.com").send()?; assert!(response.headers.get("content-type").unwrap().starts_with("text/html")); ``` ### Response #### Success Response (200) - **headers** (HashMap) - A map containing response headers, with keys in lowercase. #### Response Example ```json { "headers": { "content-type": "text/html; charset=utf-8" } } ``` ``` -------------------------------- ### TryFrom Conversions for String Source: https://docs.rs/minreq/2.14.1/minreq/type.URL.html Methods to convert ByteString, CString, and Vec into a String, validating UTF-8 data. ```APIDOC ## TryFrom Implementations ### Description Converts various byte-based types into a String, ensuring valid UTF-8 encoding. ### Methods - **try_from(ByteString)**: Converts a ByteString to a String. - **try_from(CString)**: Converts a CString to a String if valid UTF-8. - **try_from(Vec)**: Converts a Vec to a String if valid UTF-8. ### Errors - **FromUtf8Error**: Returned when conversion from ByteString or Vec fails. - **IntoStringError**: Returned when conversion from CString fails. ``` -------------------------------- ### minreq head Function Source: https://docs.rs/minreq/2.14.1/minreq/fn.head.html Alias for Request::new with `method` set to Method::Head. Use this to create a HEAD request. ```rust pub fn head>(url: T) -> Request ``` -------------------------------- ### Collection and Partitioning Source: https://docs.rs/minreq/2.14.1/minreq/struct.ResponseLazy.html Methods for consuming iterators into collections or partitioning them. ```APIDOC ## Iterator Adapters: Collection and Partitioning ### Description These methods consume iterators to create new collections or divide elements into separate collections based on a predicate. ### Methods #### `collect(self) -> B` - **Description**: Transforms an iterator into a collection. The type `B` must implement `FromIterator`. - **Type Parameters**: `B` where `B: FromIterator` - **Trait Bounds**: `Self: Sized` #### `try_collect( &mut self, ) -> <::Residual as Residual>::TryType` - **Description**: Fallibly transforms an iterator into a collection, short-circuiting if a failure (represented by `Try::Residual`) is encountered. Requires nightly Rust. - **Type Parameters**: `B` where `B: FromIterator<::Output>`, `Self::Item: Try`, `::Residual: Residual` - **Trait Bounds**: `Self: Sized` #### `collect_into(self, collection: &mut E) -> &mut E` - **Description**: Collects all items from an iterator into an existing mutable collection. Requires nightly Rust. - **Type Parameters**: `E` where `E: Extend` - **Parameters**: `collection` (&mut E) - The collection to extend. - **Trait Bounds**: `Self: Sized` #### `partition(self, f: F) -> (B, B)` - **Description**: Consumes an iterator, creating two collections. Elements for which the predicate `f` returns `true` go into the first collection, and the rest go into the second. - **Type Parameters**: `B` where `B: Default + Extend`, `F` where `F: FnMut(&Self::Item) -> bool` - **Trait Bounds**: `Self: Sized` #### `is_partitioned

(self, predicate: P) -> bool` - **Description**: Checks if the elements of this iterator are partitioned according to the given predicate, such that all elements returning `true` precede all elements returning `false`. Requires nightly Rust. - **Type Parameters**: `P` where `P: FnMut(Self::Item) -> bool` - **Trait Bounds**: `Self: Sized` ### Example Usage ```rust let data = vec![1, 2, 3, 4, 5]; // Using collect let collected_vec: Vec<_> = data.iter().cloned().collect(); // collected_vec is [1, 2, 3, 4, 5] let collected_set: std::collections::HashSet<_> = data.iter().cloned().collect(); // collected_set contains {1, 2, 3, 4, 5} // Using partition let (evens, odds): (Vec<_>, Vec<_>) = data.iter().cloned().partition(|&x| x % 2 == 0); // evens is [2, 4] // odds is [1, 3, 5] ``` ``` -------------------------------- ### Display Implementation Source: https://docs.rs/minreq/2.14.1/minreq/type.URL.html Formats the String value using a formatter. ```APIDOC ## impl Display for String ### Description Formats the value using the given formatter. ### Method fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error> ``` -------------------------------- ### Read Adapters Source: https://docs.rs/minreq/2.14.1/minreq/struct.ResponseLazy.html Methods for adapting Read instances into different forms. ```APIDOC ## POST /by_ref ### Description Creates a “by reference” adaptor for this instance of `Read`. ### Method POST ### Endpoint /by_ref ### Response #### Success Response (200) - **Self** (&mut Self) - A mutable reference to the Read adaptor. ### Response Example ```json { "adaptor": "..." } ``` ``` ```APIDOC ## POST /bytes ### Description Transforms this `Read` instance to an `Iterator` over its bytes. ### Method POST ### Endpoint /bytes ### Response #### Success Response (200) - **Bytes** (Bytes) - An iterator over the bytes of the Read instance. ### Response Example ```json { "iterator": "..." } ``` ``` ```APIDOC ## POST /chain ### Description Creates an adapter which will chain this stream with another. ### Method POST ### Endpoint /chain ### Parameters #### Request Body - **next** (R) - Required - The next Read instance to chain. ### Response #### Success Response (200) - **Chain** (Chain) - A chained adapter. ### Response Example ```json { "chained_adapter": "..." } ``` ``` ```APIDOC ## POST /take ### Description Creates an adapter which will read at most `limit` bytes from it. ### Method POST ### Endpoint /take ### Parameters #### Request Body - **limit** (u64) - Required - The maximum number of bytes to read. ### Response #### Success Response (200) - **Take** (Take) - A take adapter. ### Response Example ```json { "take_adapter": "..." } ``` ``` -------------------------------- ### From Trait Source: https://docs.rs/minreq/2.14.1/minreq/enum.Error.html Enables conversion from one type to another. ```APIDOC ## From Trait ### Description Enables conversion from one type to another. ### Method `from(t: T) -> T` ### Parameters - `t` (T): The value to convert from. ### Request Example None ### Response #### Success Response (200) - `T`: The converted value. ### Response Example None ``` -------------------------------- ### HTTP Request Methods Source: https://docs.rs/minreq Provides an overview of the available HTTP methods supported by Minreq, aliased for convenience. ```APIDOC ## HTTP Request Methods ### Description Minreq provides convenient aliases for common HTTP request methods, all originating from `Request::new`. ### Available Methods - **connect**: Alias for `Request::new` with `Method::Connect`. - **delete**: Alias for `Request::new` with `Method::Delete`. - **get**: Alias for `Request::new` with `Method::Get`. - **head**: Alias for `Request::new` with `Method::Head`. - **options**: Alias for `Request::new` with `Method::Options`. - **patch**: Alias for `Request::new` with `Method::Patch`. - **post**: Alias for `Request::new` with `Method::Post`. - **put**: Alias for `Request::new` with `Method::Put`. - **trace**: Alias for `Request::new` with `Method::Trace`. ### Usage Example ```rust // Example using the 'get' alias let response = minreq::get("https://api.example.com/data").send()?; ``` ### Response #### Success Response (200) - **data** (Any) - The response payload depends on the specific request. #### Response Example ```json { "data": "Sample response data" } ``` ``` -------------------------------- ### Into Trait Source: https://docs.rs/minreq/2.14.1/minreq/enum.Error.html Enables conversion into another type. ```APIDOC ## Into Trait ### Description Enables conversion into another type. ### Method `into(self) -> U` ### Parameters None ### Request Example None ### Response #### Success Response (200) - `U`: The converted value. ### Response Example None ``` -------------------------------- ### Read Buffer Methods Source: https://docs.rs/minreq/2.14.1/minreq/struct.ResponseLazy.html Methods for reading data into a buffer. These are experimental and nightly-only. ```APIDOC ## POST /read_buf ### Description Pull some bytes from this source into the specified buffer. ### Method POST ### Endpoint /read_buf ### Parameters #### Request Body - **buf** (BorrowedCursor<'_>) - Required - The buffer to read into. ### Response #### Success Response (200) - **Result** (Result<(), Error>) - Indicates success or failure of the read operation. ### Response Example ```json { "status": "success" } ``` ``` ```APIDOC ## POST /read_buf_exact ### Description Reads the exact number of bytes required to fill `cursor`. ### Method POST ### Endpoint /read_buf_exact ### Parameters #### Request Body - **cursor** (BorrowedCursor<'_>) - Required - The cursor to fill with exact bytes. ### Response #### Success Response (200) - **Result** (Result<(), Error>) - Indicates success or failure of the read operation. ### Response Example ```json { "status": "success" } ``` ``` -------------------------------- ### impl AsRef for String Source: https://docs.rs/minreq/2.14.1/minreq/type.URL.html Provides shared access to the underlying Path. ```APIDOC ## impl AsRef for String ### Description Provides shared access to the underlying `Path` of a `String`. This is useful for interacting with file system APIs that expect `Path`. ### Method `as_ref` ### Endpoint N/A (Method on String type) ### Request Body None ### Request Example ```rust use std::path::Path; let s = String::from("/usr/local/bin"); let path: &Path = s.as_ref(); ``` ### Response #### Success Response (200) - **&Path** - A shared reference to the `Path`. #### Response Example ```rust let path_slice: &Path = /* result of as_ref() */; ``` ``` -------------------------------- ### Try to reserve exact capacity Source: https://docs.rs/minreq/2.14.1/minreq/type.URL.html Attempts to reserve the minimum required capacity, returning a Result to handle allocation failures. ```rust use std::collections::TryReserveError; fn process_data(data: &str) -> Result { let mut output = String::new(); // Pre-reserve the memory, exiting if we can't output.try_reserve_exact(data.len())?; // Now we know this can't OOM in the middle of our complex work output.push_str(data); Ok(output) } ``` -------------------------------- ### Send HTTP Request Source: https://docs.rs/minreq/2.14.1/minreq/struct.Request.html Executes the configured HTTP request and returns the server's response or an error. ```rust pub fn send(self) -> Result ``` -------------------------------- ### Configuring Request Headers Source: https://docs.rs/minreq/2.14.1/minreq/struct.Request.html Methods for adding headers to an HTTP request. ```APIDOC ## Request Configuration - Headers ### Description Methods to add headers to an HTTP request. ### Method Chained method calls on `Request` object. ### Endpoint N/A (Configuration) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```rust let request = minreq::get("http://example.com") .with_header("User-Agent", "minreq") .with_headers(vec![("Accept", "application/json")]); ``` ### Response #### Success Response (200) None #### Response Example None ``` -------------------------------- ### ToString Implementation Source: https://docs.rs/minreq/2.14.1/minreq/enum.Method.html Converts a value implementing `Display` into a `String`. ```rust fn to_string(&self) -> String ``` -------------------------------- ### impl Debug for String Source: https://docs.rs/minreq/2.14.1/minreq/type.URL.html Formats the String for debugging purposes. ```APIDOC ## impl Debug for String ### Description Implements the `Debug` trait, allowing a `String` to be formatted using the `{:?}` format specifier for debugging output. ### Method `fmt` ### Endpoint N/A (Method on String type) ### Request Body None ### Request Example ```rust let s = String::from("debug this"); println!("Debug output: {:?}", s); ``` ### Response #### Success Response (200) - **Result<(), Error>** - The result of the formatting operation. #### Response Example ```rust // The output is typically printed to the console or captured by a formatter. // Example console output: Debug output: "debug this" ``` ``` -------------------------------- ### impl Clone for String Source: https://docs.rs/minreq/2.14.1/minreq/type.URL.html Provides functionality to create a duplicate of a String. ```APIDOC ## impl Clone for String ### Description Provides the ability to create a duplicate (clone) of a `String`. The `clone_from` method is preferred for efficiency when possible, as it can avoid reallocation. ### Method `clone`, `clone_from` ### Endpoint N/A (Method on String type) ### Request Body None ### Request Example ```rust let original = String::from("clone me"); // Using clone() let cloned_string = original.clone(); // Using clone_from() let mut target = String::new(); target.clone_from(&original); ``` ### Response #### Success Response (200) - **String** - A new `String` that is a duplicate of the original. #### Response Example ```rust let new_string: String = /* result of clone() or clone_from() */; ``` ``` -------------------------------- ### Compare Requests for Inequality in Rust Source: https://docs.rs/minreq/2.14.1/minreq/struct.Request.html Implement the `ne` method for `Request` to test for inequality using the `!=` operator. The default implementation is usually sufficient. ```rust fn ne(&self, other: &Rhs) -> bool ``` -------------------------------- ### Method Implementations Source: https://docs.rs/minreq/2.14.1/minreq/enum.Method.html Details on trait implementations for the Method enum, including Clone, Debug, Display, and PartialEq. ```APIDOC ### Trait Implementations #### impl Clone for Method ##### fn clone(&self) -> Method Returns a duplicate of the value. ##### fn clone_from(&mut self, source: &Self) Performs copy-assignment from `source`. #### impl Debug for Method ##### fn fmt(&self, f: &mut Formatter<'_>) -> Result Formats the value using the given formatter. #### impl Display for Method ##### fn fmt(&self, f: &mut Formatter<'_>) -> Result Formats the Method to the form in the HTTP request, i.e. Method::Get -> “GET”, Method::Post -> “POST”, etc. #### impl PartialEq for Method ##### fn eq(&self, other: &Method) -> bool Tests for `self` and `other` values to be equal, and is used by `==`. ##### fn ne(&self, other: &Rhs) -> bool Tests for `!=`. #### impl Eq for Method #### impl StructuralPartialEq for Method ``` -------------------------------- ### impl AsRef for String Source: https://docs.rs/minreq/2.14.1/minreq/type.URL.html Provides shared access to the underlying OsStr. ```APIDOC ## impl AsRef for String ### Description Provides shared access to the underlying `OsStr` of a `String`. This is useful for interacting with operating system APIs that expect `OsStr`. ### Method `as_ref` ### Endpoint N/A (Method on String type) ### Request Body None ### Request Example ```rust use std::ffi::OsStr; let s = String::from("path/to/file"); let os_str: &OsStr = s.as_ref(); ``` ### Response #### Success Response (200) - **&OsStr** - A shared reference to the `OsStr`. #### Response Example ```rust let os_string_slice: &OsStr = /* result of as_ref() */; ``` ``` -------------------------------- ### Create a New HTTP Request Source: https://docs.rs/minreq/2.14.1/minreq/struct.Request.html Constructs a new HTTP request with a specified method and URL. The request is not sent until `send` is called. Ensure URLs are properly encoded if urlencoding is disabled. ```rust pub fn new>(method: Method, url: T) -> Request ``` -------------------------------- ### Into Implementation Source: https://docs.rs/minreq/2.14.1/minreq/enum.Method.html Enables conversion into another type `U` if `U` implements `From`. ```rust fn into(self) -> U ``` -------------------------------- ### Set Proxy for Request Source: https://docs.rs/minreq/2.14.1/minreq/struct.Request.html Specifies the proxy server to use for this request. ```rust pub fn with_proxy(self, proxy: Proxy) -> Request ``` -------------------------------- ### impl AddAssign<&str> for String Source: https://docs.rs/minreq/2.14.1/minreq/type.URL.html Implements the '+=' operator for appending to a String. ```APIDOC ## impl AddAssign<&str> for String ### Description Implements the `+=` operator for appending to a `String`. This has the same behavior as the `push_str` method. ### Method `add_assign` (via `+=` operator) ### Endpoint N/A (Operator overload for String type) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```rust let mut s = String::from("hello"); s += " world"; ``` ### Response #### Success Response (200) None (modifies the String in place) #### Response Example N/A ``` -------------------------------- ### Connect function signature Source: https://docs.rs/minreq/2.14.1/minreq/fn.connect.html The function signature for creating a CONNECT request. ```rust pub fn connect>(url: T) -> Request ``` -------------------------------- ### Sending the Request Source: https://docs.rs/minreq/2.14.1/minreq/struct.Request.html Method to send the configured HTTP request and receive a response. ```APIDOC ## POST /api/users ### Description Sends this request to the host and returns the response. ### Method POST ### Endpoint /api/users ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```rust let request = minreq::get("http://example.com"); let response = request.send()?; ``` ### Response #### Success Response (200) - **response** (Response) - The HTTP response from the server. #### Response Example None ``` -------------------------------- ### String::from_utf8_lossy_owned Source: https://docs.rs/minreq/2.14.1/minreq/type.URL.html Converts a Vec to a String, substituting invalid UTF-8 sequences with replacement characters. This is a nightly-only experimental API. ```APIDOC ## String::from_utf8_lossy_owned ### Description Converts a `Vec` to a `String`, substituting invalid UTF-8 sequences with replacement characters. ### Method `String::from_utf8_lossy_owned` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **v** (Vec) - Required - The vector of bytes to convert. ### Request Example ```rust #![feature(string_from_utf8_lossy_owned)] let sparkle_heart = vec![240, 159, 146, 150]; let sparkle_heart = String::from_utf8_lossy_owned(sparkle_heart); assert_eq!(String::from("💖"), sparkle_heart); ``` ### Response #### Success Response (200) - **String** - The resulting String with invalid UTF-8 sequences replaced. #### Response Example ```json "💖" ``` #### Error Handling This function does not return a Result, invalid sequences are replaced. ``` -------------------------------- ### Iterate Over Lazy Response Source: https://docs.rs/minreq/2.14.1/minreq/struct.ResponseLazy.html Demonstrates how to consume a lazily-loaded response by iterating over its bytes. ```rust // This is how the normal Response works behind the scenes, and // how you might use ResponseLazy. let response = minreq::get("http://example.com").send_lazy()?; let mut vec = Vec::new(); for result in response { let (byte, length) = result?; vec.reserve(length); vec.push(byte); } ``` -------------------------------- ### Query String capacity Source: https://docs.rs/minreq/2.14.1/minreq/type.URL.html Returns the current capacity of the String in bytes. ```rust let s = String::with_capacity(10); assert!(s.capacity() >= 10); ``` -------------------------------- ### push_str Source: https://docs.rs/minreq/2.14.1/minreq/type.URL.html Appends a string slice to the end of the String. ```APIDOC ## pub fn push_str(&mut self, string: &str) ### Description Appends a given string slice onto the end of this String. ### Parameters - **string** (&str) - Required - The string slice to append. ``` -------------------------------- ### Deserialize Implementation Source: https://docs.rs/minreq/2.14.1/minreq/type.URL.html Allows deserialization of String from a Serde deserializer. ```APIDOC ## impl<'de> Deserialize<'de> for String ### Description Deserialize this value from the given Serde deserializer. ### Method fn deserialize(deserializer: D) -> Result>::Error> ``` -------------------------------- ### Request Timeout and Redirects Source: https://docs.rs/minreq/2.14.1/minreq/struct.Request.html Configuration options for request timeout and redirect handling. ```APIDOC ## Request Configuration - Timeout and Redirects ### Description Methods to configure the request timeout and redirect behavior. ### Method Chained method calls on `Request` object. ### Endpoint N/A (Configuration) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```rust let request = minreq::get("http://example.com") .with_timeout(10) .with_max_redirects(5) .with_follow_redirects(false); ``` ### Response #### Success Response (200) None #### Response Example None ```