volcengine_rust_sdk/service/iam/api_update_user_model.rs
1/*
2 * @Author: Jerry.Yang
3 * @Date: 2024-10-25 14:50:11
4 * @LastEditors: Jerry.Yang
5 * @LastEditTime: 2025-02-05 18:52:16
6 * @Description: api update user model
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::iam_user;
13
14/// Implementation of the `ApiRequest` trait for the `UpdateUserReq` struct.
15/// This implementation allows the `UpdateUserReq` struct to be formatted
16/// into a hashmap and a request body for making API requests.
17impl request::ApiRequest for iam_user::UpdateUserReq {
18 /// Converts the `UpdateUserReq` instance into a hashmap of string key - value pairs.
19 /// This hashmap can be used to construct the query parameters or form data of an API request.
20 ///
21 /// # Returns
22 /// - A `HashMap<String, String>` containing the formatted request data.
23 fn to_hashmap(&self) -> HashMap<String, String> {
24 request::Request::format_request_to_hashmap(self)
25 }
26
27 /// Converts the `UpdateUserReq` instance into a byte vector representing the request body.
28 /// In this case, an empty vector is returned as the body, indicating that there is no
29 /// specific body data for this request.
30 ///
31 /// # Returns
32 /// - A `Vec<u8>` representing the request body.
33 fn to_body(&self) -> Vec<u8> {
34 Vec::new()
35 }
36}
37
38/// Implementation of the `ApiResponse` trait for the `UpdateUserResp` struct.
39/// This implementation is responsible for converting an HTTP response into the `UpdateUserResp` struct.
40impl response::ApiResponse for iam_user::UpdateUserResp {
41 /// Converts an HTTP response into the `UpdateUserResp` struct.
42 /// It first parses the JSON response body, then updates the current `UpdateUserResp` instance
43 /// with the parsed data. If there is an error during parsing, it returns an `Error` struct.
44 ///
45 /// # Arguments
46 /// - `&mut self`: A mutable reference to the `UpdateUserResp` instance.
47 /// - `http_response`: A `reqwest::Response` containing the HTTP response data.
48 ///
49 /// # Returns
50 /// - On success, returns `Ok(())`.
51 /// - On error, returns an `Error` struct indicating the reason for the failure,
52 /// such as a parsing error.
53 async fn to_struct(&mut self, http_response: reqwest::Response) -> Result<(), error::Error> {
54 // Parse the JSON response body into an `UpdateUserResp` struct.
55 // If the parsing fails, map the error to an `ErrParseResponse` error type.
56 let parsed_response: volcengine_sdk_protobuf::protobuf::iam_user::UpdateUserResp =
57 http_response
58 .json()
59 .await
60 .map_err(|e| error::Error::ErrParseResponse(e))?;
61
62 // Update the current `UpdateUserResp` instance with the parsed response data.
63 *self = parsed_response;
64
65 // Return `Ok(())` to indicate successful conversion of the HTTP response to the struct.
66 Ok(())
67 }
68}