twilight_http/request/application/monetization/
consume_entitlement.rs1use crate::{
2 Client, Error, Response,
3 request::{Request, TryIntoRequest},
4 response::{ResponseFuture, marker::EmptyBody},
5 routing::Route,
6};
7use std::future::IntoFuture;
8use twilight_model::id::{
9 Id,
10 marker::{ApplicationMarker, EntitlementMarker},
11};
12
13#[must_use = "requests must be configured and executed"]
18pub struct ConsumeEntitlement<'a> {
19 application_id: Id<ApplicationMarker>,
20 entitlement_id: Id<EntitlementMarker>,
21 http: &'a Client,
22}
23
24impl<'a> ConsumeEntitlement<'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 ConsumeEntitlement<'_> {
39 type Output = Result<Response<EmptyBody>, Error>;
40
41 type IntoFuture = ResponseFuture<EmptyBody>;
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 ConsumeEntitlement<'_> {
54 fn try_into_request(self) -> Result<Request, Error> {
55 Ok(Request::from_route(&Route::ConsumeEntitlement {
56 application_id: self.application_id.get(),
57 entitlement_id: self.entitlement_id.get(),
58 }))
59 }
60}