1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
use crate::{
client::Client,
error::Error as HttpError,
request::{Request, TryIntoRequest},
response::{marker::EmptyBody, ResponseFuture},
routing::Route,
};
use serde::Serialize;
use twilight_model::{
channel::stage_instance::PrivacyLevel,
id::{marker::ChannelMarker, Id},
};
use twilight_validate::request::{stage_topic as validate_stage_topic, ValidationError};
#[derive(Serialize)]
struct CreateStageInstanceFields<'a> {
channel_id: Id<ChannelMarker>,
#[serde(skip_serializing_if = "Option::is_none")]
privacy_level: Option<PrivacyLevel>,
topic: &'a str,
}
#[must_use = "requests must be configured and executed"]
pub struct CreateStageInstance<'a> {
fields: CreateStageInstanceFields<'a>,
http: &'a Client,
}
impl<'a> CreateStageInstance<'a> {
pub(crate) fn new(
http: &'a Client,
channel_id: Id<ChannelMarker>,
topic: &'a str,
) -> Result<Self, ValidationError> {
validate_stage_topic(topic)?;
Ok(Self {
fields: CreateStageInstanceFields {
channel_id,
privacy_level: None,
topic,
},
http,
})
}
pub const fn privacy_level(mut self, privacy_level: PrivacyLevel) -> Self {
self.fields.privacy_level = Some(privacy_level);
self
}
pub fn exec(self) -> ResponseFuture<EmptyBody> {
let http = self.http;
match self.try_into_request() {
Ok(request) => http.request(request),
Err(source) => ResponseFuture::error(source),
}
}
}
impl TryIntoRequest for CreateStageInstance<'_> {
fn try_into_request(self) -> Result<Request, HttpError> {
let mut request = Request::builder(&Route::CreateStageInstance);
request = request.json(&self.fields)?;
Ok(request.build())
}
}