Skip to main content

twilight_http/request/guild/
get_guild_onboarding.rs

1use std::future::IntoFuture;
2
3use crate::{
4    Client, Error,
5    request::{Request, TryIntoRequest},
6    routing::Route,
7};
8#[cfg(not(target_os = "wasi"))]
9use crate::{Response, response::ResponseFuture};
10use twilight_model::{
11    guild::onboarding::Onboarding,
12    id::{Id, marker::GuildMarker},
13};
14
15/// Get the onboarding information for a guild.
16///
17/// # Examples
18///
19/// ```no_run
20/// use twilight_http::Client;
21/// use twilight_model::id::Id;
22///
23/// # #[tokio::main]
24/// async fn main() -> Result<(), Box<dyn std::error::Error>> {
25/// let client = Client::new("token".to_owned());
26///
27/// let guild_id = Id::new(101);
28/// let onboarding = client.guild_onboarding(guild_id).await?.model().await?;
29///
30/// for prompt in onboarding.prompts {
31///     println!("Prompt: {}", prompt.title);
32/// }
33/// # Ok(()) }
34/// ```
35pub struct GetGuildOnboarding<'a> {
36    guild_id: Id<GuildMarker>,
37    http: &'a Client,
38}
39
40impl<'a> GetGuildOnboarding<'a> {
41    pub(crate) const fn new(http: &'a Client, guild_id: Id<GuildMarker>) -> Self {
42        Self { guild_id, http }
43    }
44}
45
46#[cfg(not(target_os = "wasi"))]
47impl IntoFuture for GetGuildOnboarding<'_> {
48    type Output = Result<Response<Onboarding>, Error>;
49
50    type IntoFuture = ResponseFuture<Onboarding>;
51
52    fn into_future(self) -> Self::IntoFuture {
53        let http = self.http;
54
55        match self.try_into_request() {
56            Ok(request) => http.request(request),
57            Err(source) => ResponseFuture::error(source),
58        }
59    }
60}
61
62impl TryIntoRequest for GetGuildOnboarding<'_> {
63    fn try_into_request(self) -> Result<Request, Error> {
64        let request = Request::from_route(&Route::GetGuildOnboarding {
65            guild_id: self.guild_id.get(),
66        });
67
68        Ok(request)
69    }
70}