twilight_http/request/guild/
get_guild_onboarding.rs

1use std::future::IntoFuture;
2
3use twilight_model::{
4    guild::onboarding::Onboarding,
5    id::{marker::GuildMarker, Id},
6};
7
8use crate::{
9    request::{Request, TryIntoRequest},
10    response::ResponseFuture,
11    routing::Route,
12    Client, Error, Response,
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
46impl IntoFuture for GetGuildOnboarding<'_> {
47    type Output = Result<Response<Onboarding>, Error>;
48
49    type IntoFuture = ResponseFuture<Onboarding>;
50
51    fn into_future(self) -> Self::IntoFuture {
52        let http = self.http;
53
54        match self.try_into_request() {
55            Ok(request) => http.request(request),
56            Err(source) => ResponseFuture::error(source),
57        }
58    }
59}
60
61impl TryIntoRequest for GetGuildOnboarding<'_> {
62    fn try_into_request(self) -> Result<Request, Error> {
63        let request = Request::from_route(&Route::GetGuildOnboarding {
64            guild_id: self.guild_id.get(),
65        });
66
67        Ok(request)
68    }
69}