Skip to main content

twilight_http/request/application/monetization/
get_entitlement.rs

1use crate::{
2    Client, Error, Response,
3    request::{Request, TryIntoRequest},
4    response::ResponseFuture,
5    routing::Route,
6};
7use std::future::IntoFuture;
8use twilight_model::{
9    application::monetization::Entitlement,
10    id::{
11        Id,
12        marker::{ApplicationMarker, EntitlementMarker},
13    },
14};
15
16/// Get an entitlement.
17#[must_use = "requests must be configured and executed"]
18pub struct GetEntitlement<'a> {
19    application_id: Id<ApplicationMarker>,
20    entitlement_id: Id<EntitlementMarker>,
21    http: &'a Client,
22}
23
24impl<'a> GetEntitlement<'a> {
25    pub(crate) const fn new(
26        http: &'a Client,
27        application_id: Id<ApplicationMarker>,
28        entitlement_id: Id<EntitlementMarker>,
29    ) -> Self {
30        Self {
31            application_id,
32            entitlement_id,
33            http,
34        }
35    }
36}
37
38impl IntoFuture for GetEntitlement<'_> {
39    type Output = Result<Response<Entitlement>, Error>;
40
41    type IntoFuture = ResponseFuture<Entitlement>;
42
43    fn into_future(self) -> Self::IntoFuture {
44        let http = self.http;
45
46        match self.try_into_request() {
47            Ok(request) => http.request(request),
48            Err(source) => ResponseFuture::error(source),
49        }
50    }
51}
52
53impl TryIntoRequest for GetEntitlement<'_> {
54    fn try_into_request(self) -> Result<Request, Error> {
55        Ok(Request::from_route(&Route::GetEntitlement {
56            application_id: self.application_id.get(),
57            entitlement_id: self.entitlement_id.get(),
58        }))
59    }
60}