Trait RequestModifiers

Source
pub trait RequestModifiers: RequestInfo {
    // Provided methods
    fn create_endpoint(endpoint: &str) -> String { ... }
    fn add_header_if(
        request_builder: RequestBuilder,
        key: &str,
        value: &str,
        closure: impl FnOnce() -> bool,
    ) -> RequestBuilder { ... }
}
Expand description

This trait provides methods for modifying the struct in a specific way:

Provided Methods§

Source

fn create_endpoint(endpoint: &str) -> String

Joins the given endpoint with the base URL.

§Arguments
  • endpoint - The endpoint to join with the base URL.
§Returns

The joined URL as a String.

Source

fn add_header_if( request_builder: RequestBuilder, key: &str, value: &str, closure: impl FnOnce() -> bool, ) -> RequestBuilder

Conditionally adds a header to the given RequestBuilder based on the result of a closure.

If the closure returns true, the specified header with the provided key and value will be added to the request. If the closure returns false, no changes will be made to the request.

§Arguments
  • request_builder - The RequestBuilder to add the header to.
  • key - The key of the header to be added.
  • value - The value of the header to be added.
  • closure - A closure that determines whether the header should be added. It should take no arguments and return a boolean value.
§Returns

The modified RequestBuilder with the header added if the closure returns true, otherwise the original RequestBuilder without any modifications.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§