1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/*
* @Author: Jerry.Yang
* @Date: 2024-11-05 10:39:54
* @LastEditors: Jerry.Yang
* @LastEditTime: 2025-02-06 11:16:35
* @Description: Implementation of request and response handling for describing database accounts.
*/
use crate::volcengine::error::error;
use crate::volcengine::request::request::RequestVolcengine;
use crate::volcengine::request::{request, response};
use std::collections::HashMap;
use volcengine_sdk_protobuf::protobuf::rds_account;
/// Implementation of the `ApiRequest` trait for the `DescribeDbAccountsReq` structure.
/// This implementation provides the necessary methods to convert the request into a format suitable for sending over HTTP.
impl request::ApiRequest for rds_account::DescribeDbAccountsReq {
/// Converts the request into a `HashMap` of headers.
/// This method formats the request parameters into a `HashMap` that can be used as query parameters in the HTTP request.
/// The `Request::format_request_to_hashmap` method is used to handle the conversion.
fn to_hashmap(&self) -> HashMap<String, String> {
request::Request::format_request_to_hashmap(self)
}
/// Serializes the request into a byte vector to be sent as the request body.
/// For this specific request, no request body is required, so an empty byte vector is returned.
fn to_body(&self) -> Vec<u8> {
Vec::new()
}
}
/// Implementation of the `ApiResponse` trait for the `DescribeDbAccountsResp` structure.
/// This implementation provides the necessary methods to parse the HTTP response into a structured response object.
impl response::ApiResponse for rds_account::DescribeDbAccountsResp {
/// Deserializes the HTTP response into a structured response object.
/// This method takes an `http_response` object, parses its JSON body, and updates the current response object with the parsed data.
///
/// # Arguments
/// * `http_response` - The HTTP response object received from the server.
///
/// # Returns
/// * `Result<(), error::Error>` - Returns `Ok(())` if the response is successfully parsed, or an error if parsing fails.
async fn to_struct(&mut self, http_response: reqwest::Response) -> Result<(), error::Error> {
// Parse the JSON response body into the expected structure.
let parsed_response: volcengine_sdk_protobuf::protobuf::rds_account::DescribeDbAccountsResp =
http_response
.json()
.await
.map_err(|e| error::Error::ErrParseResponse(e))?;
// Update the current response object with the parsed data.
*self = parsed_response;
// Return successfully if no errors occurred.
Ok(())
}
}