Skip to content

Commit 2d7312c

Browse files
committed
bu...
1 parent 576004d commit 2d7312c

File tree

5 files changed

+27
-19
lines changed

5 files changed

+27
-19
lines changed

examples/get_user.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
use twitch_api::{helix::users::GetUsersRequest, HelixClient};
1+
use twitch_api::{
2+
helix::users::{GetUsersRequest, User},
3+
HelixClient,
4+
};
25
use twitch_oauth2::{AccessToken, UserToken};
36

47
fn main() {

src/helix/client.rs

+10-11
Original file line numberDiff line numberDiff line change
@@ -101,17 +101,19 @@ impl<'a, C: crate::HttpClient<'a>> HelixClient<'a, C> {
101101
/// # }
102102
/// # // fn main() {run()}
103103
/// ```
104-
pub async fn req_get<R, D, T>(
104+
pub async fn req_get<'t, R, D, T>(
105105
&'a self,
106106
request: R,
107-
token: &T,
107+
token: &'t T,
108108
) -> Result<
109-
Response<R, yoke::Yoke<<R as Request>::Response<'static>, std::rc::Rc<[u8]>>>,
109+
Response<R, yoke::Yoke<D, std::rc::Rc<[u8]>>>,
110110
ClientRequestError<<C as crate::HttpClient<'a>>::Error>,
111111
>
112112
where
113-
R: Request<Response<'static> = D> + RequestGet,
114-
D: for<'b> serde::de::Deserialize<'b> + for<'b> yoke::Yokeable<'b, Output = D> + PartialEq,
113+
for<'r> R: Request + RequestGet<Response<'r> = D> + Request<Response<'r> = D>,
114+
for<'b> yoke::trait_hack::YokeTraitHack<<D as yoke::Yokeable<'b>>::Output>:
115+
serde::de::Deserialize<'b>,
116+
for<'b> D: PartialEq + yoke::Yokeable<'b, Output = D>,
115117
T: TwitchToken + ?Sized,
116118
C: Send,
117119
{
@@ -132,18 +134,15 @@ impl<'a, C: crate::HttpClient<'a>> HelixClient<'a, C> {
132134
let mut other = None;
133135
let resp: yoke::Yoke<D, _> = yoke::Yoke::try_attach_to_cart(
134136
body,
135-
|body| -> Result<
136-
<D as yoke::Yokeable<'static>>::Output,
137-
ClientRequestError<<C as crate::HttpClient<'a>>::Error>,
138-
> {
137+
|body| -> Result<_, ClientRequestError<<C as crate::HttpClient<'a>>::Error>> {
139138
let response = http::Response::from_parts(parts, body);
140-
let Response {
139+
let Response::<_, <R as Request>::Response<'_>> {
141140
data,
142141
pagination: pagination_inner,
143142
request: request_inner,
144143
total: total_inner,
145144
other: other_inner,
146-
} = todo!();//<R>::parse_response(Some(request), &uri, &response)?;
145+
} = <R as RequestGet>::parse_response(Some(request), &uri, &response)?;
147146
pagination = pagination_inner;
148147
request_opt = request_inner;
149148
total = total_inner;

src/helix/endpoints/users/get_users.rs

+9-2
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ pub struct GetUsersRequest {
5959
/// Return Values for [Get Users](super::get_users)
6060
///
6161
/// [`get-users`](https://dev.twitch.tv/docs/api/reference#get-users)
62-
#[derive(PartialEq, Deserialize, Serialize, Debug, Clone)]
62+
#[derive(PartialEq, Deserialize, Serialize, Debug, Clone, yoke::Yokeable)]
6363
#[cfg_attr(feature = "deny_unknown_fields", serde(deny_unknown_fields))]
6464
#[non_exhaustive]
6565
pub struct User<'a> {
@@ -144,5 +144,12 @@ fn test_request() {
144144
"https://api.twitch.tv/helix/users?id=44322889"
145145
);
146146

147-
dbg!(GetUsersRequest::parse_response(Some(req), &uri, &http_response).unwrap());
147+
{
148+
let this = dbg!(GetUsersRequest::parse_response(Some(req), &uri, &http_response).unwrap());
149+
let ref this = this.data.get(0).unwrap().created_at;
150+
match *this {
151+
Cow::Borrowed(_) => dbg!("borrow"),
152+
Cow::Owned(_) => dbg!("owned"),
153+
}
154+
};
148155
}

src/helix/request.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ pub trait Request: serde::Serialize {
1818
#[cfg(feature = "twitch_oauth2")]
1919
const OPT_SCOPE: &'static [twitch_oauth2::Scope] = &[];
2020
/// Response type. twitch's response will deserialize to this.
21-
type Response<'a>: serde::de::Deserialize<'a> + PartialEq + 'a;
21+
type Response<'a>: for<'de> serde::de::Deserialize<'de> + PartialEq + 'a;
2222
/// Defines layout of the url parameters.
2323
fn query(&self) -> Result<String, errors::SerializeError> { ser::to_string(&self) }
2424
/// Returns full URI for the request, including query parameters.
@@ -396,12 +396,12 @@ pub trait RequestGet: Request {
396396
response: &'b http::Response<&'a [u8]>,
397397
) -> Result<Response<Self, <Self as Request>::Response<'a>>, HelixRequestGetError>
398398
where
399-
Self: Sized + 'a,
399+
Self: Sized,
400400
{
401401
let text = std::str::from_utf8(response.body()).map_err(|e| {
402402
HelixRequestGetError::Utf8Error(response.body().to_vec(), e, uri.clone())
403403
})?;
404-
//eprintln!("\n\nmessage is ------------ {} ------------", text);
404+
//eprintln!("\n\nmessage is ----------- {} ------------", text);
405405
if let Ok(HelixRequestError {
406406
error,
407407
status,

src/helix/response.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ use super::{Cursor, Request};
33

44
/// Response retrieved from endpoint. Data is the type in [`Request::Response`]
55
#[non_exhaustive]
6-
pub struct Response<R, D>
7-
where R: Request {
6+
pub struct Response<R, D> {
87
/// Twitch's response field for `data`.
98
pub data: D,
109
/// A cursor value, to be used in a subsequent request to specify the starting point of the next set of results.

0 commit comments

Comments
 (0)