volcengine_rust_sdk/service/rds/api_create_db_account_model.rs
1use crate::volcengine::error::error;
2use crate::volcengine::request::{request, response};
3use std::collections::HashMap;
4use volcengine_sdk_protobuf::protobuf::rds_account;
5
6/// Implements the `ApiRequest` trait for the `CreateDbAccountReq` struct.
7/// This implementation allows the `CreateDbAccountReq` struct to be formatted
8/// into a format suitable for making API requests, including converting it to
9/// a hashmap for query parameters and a byte vector for the request body.
10impl request::ApiRequest for rds_account::CreateDbAccountReq {
11 /// Converts the `CreateDbAccountReq` instance into a hashmap of string key - value pairs.
12 /// This hashmap can be used to construct query parameters for an API request.
13 /// In this implementation, an empty hashmap is returned as the current logic
14 /// comments out the actual formatting and simply creates a new, empty hashmap.
15 ///
16 /// # Returns
17 /// - A `HashMap<String, String>` containing the formatted request data (empty in this case).
18 fn to_hashmap(&self) -> HashMap<String, String> {
19 // This line would format the request into a hashmap if uncommented.
20 // request::Request::format_request_to_hashmap(self)
21 HashMap::new()
22 }
23
24 /// Converts the `CreateDbAccountReq` instance into a byte vector representing the request body.
25 /// It serializes the `CreateDbAccountReq` struct into a JSON byte vector.
26 /// If the serialization fails, the program will panic as `unwrap` is used.
27 ///
28 /// # Returns
29 /// - A `Vec<u8>` representing the serialized JSON data of the request body.
30 fn to_body(&self) -> Vec<u8> {
31 serde_json::to_vec(self).unwrap()
32 // This line would return an empty vector if uncommented.
33 // Vec::new()
34 }
35}
36
37/// Implements the `ApiResponse` trait for the `CreateDbAccountResp` struct.
38/// This implementation is responsible for converting an HTTP response into the `CreateDbAccountResp` struct.
39impl response::ApiResponse for rds_account::CreateDbAccountResp {
40 /// Converts an HTTP response into the `CreateDbAccountResp` struct.
41 /// It first parses the JSON response body, then updates the current `CreateDbAccountResp` instance
42 /// with the parsed data. If there is an error during parsing, it returns an `Error` struct.
43 ///
44 /// # Arguments
45 /// - `&mut self`: A mutable reference to the `CreateDbAccountResp` instance.
46 /// - `http_response`: A `reqwest::Response` containing the HTTP response data.
47 ///
48 /// # Returns
49 /// - On success, returns `Ok(())`.
50 /// - On error, returns an `Error` struct indicating the reason for the failure,
51 /// such as a parsing error.
52 async fn to_struct(&mut self, http_response: reqwest::Response) -> Result<(), error::Error> {
53 // Parse the JSON response body into a `CreateDbAccountResp` struct.
54 // If the parsing fails, map the error to an `ErrParseResponse` error type.
55 let parsed_response: volcengine_sdk_protobuf::protobuf::rds_account::CreateDbAccountResp =
56 http_response
57 .json()
58 .await
59 .map_err(|e| error::Error::ErrParseResponse(e))?;
60
61 // Update the current `CreateDbAccountResp` instance with the parsed response data.
62 *self = parsed_response;
63
64 // Return `Ok(())` to indicate successful conversion of the HTTP response to the struct.
65 Ok(())
66 }
67}