volcengine_rust_sdk/service/ecs/
api_describe_regions_model.rs

1/*
2 * @Author: Jerry.Yang
3 * @Date: 2024-10-29 10:25:09
4 * @LastEditors: Jerry.Yang
5 * @LastEditTime: 2025-02-06 16:50:20
6 * @Description: api describe instances model
7 */
8use crate::volcengine::error::error;
9use crate::volcengine::request::request;
10use crate::volcengine::request::request::RequestVolcengine;
11use crate::volcengine::request::response;
12use std::collections::HashMap;
13use volcengine_sdk_protobuf::protobuf::ecs_zone;
14
15// Implement the ApiRequest trait for the DescribeRegionsReq struct.
16// This allows the struct to be used as a request object in API calls.
17impl request::ApiRequest for ecs_zone::DescribeRegionsReq {
18    // Converts the request into a HashMap of key-value pairs for use in HTTP requests.
19    // This method is typically used when sending the request to the API server.
20    fn to_hashmap(&self) -> HashMap<String, String> {
21        request::Request::format_request_to_hashmap(self)
22    }
23
24    // Prepares the request body as a byte vector.
25    // For this request, the body is an empty vector since it's a GET request.
26    fn to_body(&self) -> Vec<u8> {
27        Vec::new()
28    }
29}
30
31// Implement the ApiResponse trait for the DescribeRegionsResp struct.
32// This allows the struct to parse HTTP responses and convert them into a structured object.
33impl response::ApiResponse for ecs_zone::DescribeRegionsResp {
34    // Converts the HTTP response into a structured response object.
35    // This method handles parsing the JSON response from the API server.
36    async fn to_struct(&mut self, http_response: reqwest::Response) -> Result<(), error::Error> {
37        // Parse the JSON response from the HTTP response.
38        // The `json()` method deserializes the response body into the target type.
39        let parsed_response: volcengine_sdk_protobuf::protobuf::ecs_zone::DescribeRegionsResp =
40            http_response
41                .json()
42                .await
43                .map_err(|e| error::Error::ErrParseResponse(e))?; // Handle JSON parsing errors
44
45        // Replace the current `self` with the parsed response.
46        *self = parsed_response;
47
48        // Return Ok(()) to indicate successful parsing.
49        Ok(())
50    }
51}