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