tencent_sdk/core/
endpoint.rs

1use crate::core::TencentCloudError;
2use serde::de::DeserializeOwned;
3use serde_json::Value;
4use std::borrow::Cow;
5
6pub trait Endpoint {
7    type Output: DeserializeOwned + Send + Sync + 'static;
8
9    fn service(&self) -> Cow<'static, str>;
10    fn action(&self) -> Cow<'static, str>;
11    fn version(&self) -> Cow<'static, str>;
12
13    fn region(&self) -> Option<Cow<'_, str>> {
14        None
15    }
16
17    fn scheme(&self) -> Cow<'static, str> {
18        Cow::Borrowed("https")
19    }
20
21    fn host(&self) -> Cow<'_, str> {
22        let service = self.service();
23        Cow::Owned(format!("{}.tencentcloudapi.com", service))
24    }
25
26    fn path(&self) -> Cow<'_, str> {
27        Cow::Borrowed("/")
28    }
29
30    fn payload(&self) -> Value {
31        Value::Object(Default::default())
32    }
33
34    fn extra_headers(&self) -> Option<Vec<(Cow<'_, str>, Cow<'_, str>)>> {
35        None
36    }
37
38    fn parse(&self, body: Value) -> Result<Self::Output, TencentCloudError> {
39        Ok(serde_json::from_value(body)?)
40    }
41}