RequestVolcengine

Trait RequestVolcengine 

Source
pub trait RequestVolcengine {
    // Required methods
    fn format_request_to_hashmap<T: Serialize>(
        request: &T,
    ) -> HashMap<String, String>;
    fn send<T: ApiRequest>(
        &self,
        request: T,
    ) -> impl Future<Output = Result<Response, Error>>;
}
Expand description

Trait for handling requests to the Volcengine API.

This trait defines the core methods required for interacting with the Volcengine API. It includes a method to format requests into a HashMap and another to send the API request and handle the response. Implementing this trait allows types to convert requests into the appropriate format and handle communication with the Volcengine service.

Required Methods§

Source

fn format_request_to_hashmap<T: Serialize>( request: &T, ) -> HashMap<String, String>

Formats the provided request into a HashMap<String, String>.

This method takes a serializable request object and converts it into a HashMap where each field in the request is represented as a key-value pair. It filters out any null or empty values to ensure only valid fields are included in the resulting map. This can be useful for serializing data that will be sent to the Volcengine API, making it easier to construct HTTP request bodies or query parameters.

§Parameters
  • request: A reference to a serializable object (must implement serde::Serialize).
§Returns
  • HashMap<String, String>: A HashMap where the keys are field names and the values are their corresponding values from the request. Null or empty values are excluded.
§Example
let request = MyRequest { ... };
let formatted_map = request.format_request_to_hashmap(&request);
Source

fn send<T: ApiRequest>( &self, request: T, ) -> impl Future<Output = Result<Response, Error>>

Sends an API request to the Volcengine API and returns the response.

This method is responsible for sending the request to the Volcengine API and returning the response, or an error if something goes wrong during the request. The request must implement the ApiRequest trait, which ensures that the necessary data can be serialized and transmitted to the API.

§Parameters
  • request: An instance that implements the ApiRequest trait. This represents the request data to be sent.
§Returns
  • Result<reqwest::Response, error::Error>: A Result containing either the reqwest::Response if the request was successful, or an error::Error if something went wrong during the request.
§Example
let request = MyApiRequest { ... };
let response = my_request_handler.send(request).await;

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§

Source§

impl RequestVolcengine for Request

Implementation of the RequestVolcengine trait for the Request struct.

This block provides methods for formatting the request into a HashMap and sending an API request. The methods implement the functionality needed to interact with the Volcengine API. The Request struct is adapted to handle serialization and request sending according to the Volcengine API’s requirements.

The methods in this implementation allow for easy conversion of the request data to a format expected by the Volcengine API and also provide a way to send the request over HTTP using the reqwest library.

§Example Usage

let request = Request::builder()
    .config(config)
    .client_info(client_info)
    .handles(handles)
    .operation(operation)
    .build();

let result = request.send(api_request);