Skip to main content

ve_tos_rust_sdk/asynchronous/
control.rs

1/*
2 * Copyright (c) 2025 Beijing Volcano Engine Technology Co., Ltd.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16use crate::asynchronous::http::HttpResponse;
17use crate::asynchronous::internal::{read_response_string, OutputParser};
18use crate::common::{Meta, RequestInfo};
19use crate::control::{DeleteQosPolicyInput, DeleteQosPolicyOutput, GetQosPolicyInput, GetQosPolicyOutput, PutQosPolicyInput, PutQosPolicyOutput};
20use crate::error::TosError;
21use crate::http::HttpRequest;
22use async_trait::async_trait;
23
24#[async_trait]
25pub trait ControlAPI {
26    async fn put_qos_policy(&self, input: &PutQosPolicyInput) -> Result<PutQosPolicyOutput, TosError>;
27    async fn get_qos_policy(&self, input: &GetQosPolicyInput) -> Result<GetQosPolicyOutput, TosError>;
28    async fn delete_qos_policy(&self, input: &DeleteQosPolicyInput) -> Result<DeleteQosPolicyOutput, TosError>;
29}
30
31#[async_trait]
32impl OutputParser for PutQosPolicyOutput {
33    async fn parse<B>(_: HttpRequest<'_, B>, _: HttpResponse, request_info: RequestInfo, _: Meta) -> Result<Self, TosError>
34    where
35        B: Send,
36    {
37        Ok(Self {
38            request_info,
39        })
40    }
41}
42
43#[async_trait]
44impl OutputParser for GetQosPolicyOutput {
45    async fn parse<B>(_: HttpRequest<'_, B>, response: HttpResponse, request_info: RequestInfo, _: Meta) -> Result<Self, TosError>
46    where
47        B: Send,
48    {
49        let policy = read_response_string(response).await?;
50        Ok(Self {
51            request_info,
52            policy,
53        })
54    }
55}
56
57#[async_trait]
58impl OutputParser for DeleteQosPolicyOutput {
59    async fn parse<B>(_: HttpRequest<'_, B>, _: HttpResponse, request_info: RequestInfo, _: Meta) -> Result<Self, TosError>
60    where
61        B: Send,
62    {
63        Ok(Self {
64            request_info,
65        })
66    }
67}