aliyun_log_rust_sdk/client/project/
create_project.rs1use super::*;
2use crate::RequestErrorKind;
3use serde::Serialize;
4
5impl crate::client::Client {
6 pub fn create_project(&self, project_name: impl AsRef<str>) -> CreateProjectRequestBuilder {
31 CreateProjectRequestBuilder {
32 handle: self.handle.clone(),
33 project_name: project_name.as_ref().to_string(),
34 description: None,
35 resource_group_id: None,
36 data_redundancy_type: None,
37 recycle_bin_enabled: None,
38 }
39 }
40}
41
42pub struct CreateProjectRequestBuilder {
43 handle: HandleRef,
44 project_name: String,
45 description: Option<String>,
46 resource_group_id: Option<String>,
47 data_redundancy_type: Option<String>,
48 recycle_bin_enabled: Option<bool>,
49}
50
51impl CreateProjectRequestBuilder {
52 #[must_use = "the result future must be awaited"]
53 pub fn send(self) -> ResponseResultBoxFuture<()> {
54 Box::pin(async move {
55 let (handle, request) = self.build()?;
56 handle.send(request).await
57 })
58 }
59
60 pub fn description(mut self, description: impl Into<String>) -> Self {
66 self.description = Some(description.into());
67 self
68 }
69
70 pub fn resource_group_id(mut self, resource_group_id: impl Into<String>) -> Self {
76 self.resource_group_id = Some(resource_group_id.into());
77 self
78 }
79
80 pub fn data_redundancy_type(mut self, data_redundancy_type: impl Into<String>) -> Self {
88 self.data_redundancy_type = Some(data_redundancy_type.into());
89 self
90 }
91
92 pub fn recycle_bin_enabled(mut self, enabled: bool) -> Self {
98 self.recycle_bin_enabled = Some(enabled);
99 self
100 }
101
102 fn build(self) -> BuildResult<CreateProjectRequest> {
103 check_required!(("description", self.description));
104 Ok((
105 self.handle,
106 CreateProjectRequest {
107 project_name: self.project_name,
108 description: self.description.unwrap(),
109 resource_group_id: self.resource_group_id,
110 data_redundancy_type: self.data_redundancy_type,
111 recycle_bin_enabled: self.recycle_bin_enabled,
112 },
113 ))
114 }
115}
116
117#[derive(Serialize)]
118struct CreateProjectRequest {
119 #[serde(rename = "projectName")]
120 project_name: String,
121 description: String,
122 #[serde(rename = "resourceGroupId", skip_serializing_if = "Option::is_none")]
123 resource_group_id: Option<String>,
124 #[serde(rename = "dataRedundancyType", skip_serializing_if = "Option::is_none")]
125 data_redundancy_type: Option<String>,
126 #[serde(rename = "recycleBinEnabled", skip_serializing_if = "Option::is_none")]
127 recycle_bin_enabled: Option<bool>,
128}
129
130impl Request for CreateProjectRequest {
131 const HTTP_METHOD: http::Method = http::Method::POST;
132 const CONTENT_TYPE: Option<http::HeaderValue> = Some(LOG_JSON);
133 type ResponseBody = ();
134
135 fn project(&self) -> Option<&str> {
136 None
137 }
138
139 fn path(&self) -> &str {
140 "/"
141 }
142
143 fn body(&self) -> crate::Result<Option<bytes::Bytes>, RequestError> {
144 let json = serde_json::to_string(&self).map_err(RequestErrorKind::JsonEncode)?;
145 Ok(Some(bytes::Bytes::from(json)))
146 }
147}