Skip to content

Commit 4d0ae22

Browse files
committed
nope
1 parent ea356be commit 4d0ae22

File tree

9 files changed

+115
-568
lines changed

9 files changed

+115
-568
lines changed

Cargo.lock

Lines changed: 1 addition & 448 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 56 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ rust-version = "1.64"
2323

2424

2525
[workspace]
26-
members = ["xtask", "examples/*"]
26+
members = ["xtask", ] #"examples/*"]
2727
exclude = ["twitch_types", "twitch_oauth2"]
2828

2929
[workspace.dependencies]
@@ -106,61 +106,61 @@ hyper = "0.14.23"
106106
[build-dependencies]
107107
version_check = "0.9.4"
108108

109-
[[example]]
110-
name = "automod_check"
111-
path = "examples/automod_check.rs"
112-
required-features = ["reqwest", "helix"]
113-
114-
[[example]]
115-
name = "get_channel_status"
116-
path = "examples/get_channel_status.rs"
117-
required-features = ["reqwest", "helix"]
118-
119-
[[example]]
120-
name = "get_users"
121-
path = "examples/get_users.rs"
122-
required-features = ["reqwest", "helix"]
123-
124-
125-
[[example]]
126-
name = "get_moderation"
127-
path = "examples/get_moderation.rs"
128-
required-features = ["reqwest", "helix"]
129-
130-
[[example]]
131-
name = "get_streams_and_chatters"
132-
path = "examples/get_streams_and_chatters.rs"
133-
required-features = ["reqwest", "helix", "tmi"]
134-
135-
[[example]]
136-
name = "modify_channel"
137-
path = "examples/modify_channel.rs"
138-
139-
required-features = ["reqwest", "helix"]
140-
[[example]]
141-
name = "client"
142-
path = "examples/client.rs"
143-
required-features = ["reqwest", "helix"]
144-
145-
[[example]]
146-
name = "channel_information"
147-
path = "examples/channel_information.rs"
148-
required-features = ["reqwest", "helix"]
149-
150-
[[example]]
151-
name = "channel_information_custom"
152-
path = "examples/channel_information_custom.rs"
153-
required-features = ["reqwest", "helix", "unsupported"]
154-
155-
[[example]]
156-
name = "followed_streams"
157-
path = "examples/followed_streams.rs"
158-
required-features = ["reqwest", "helix"]
159-
160-
[[example]]
161-
name = "mock_api"
162-
path = "examples/mock_api.rs"
163-
required-features = ["reqwest", "helix", "mock_api", "twitch_oauth2/mock_api"]
109+
# [[example]]
110+
# name = "automod_check"
111+
# path = "examples/automod_check.rs"
112+
# required-features = ["reqwest", "helix"]
113+
114+
# [[example]]
115+
# name = "get_channel_status"
116+
# path = "examples/get_channel_status.rs"
117+
# required-features = ["reqwest", "helix"]
118+
119+
# [[example]]
120+
# name = "get_users"
121+
# path = "examples/get_users.rs"
122+
# required-features = ["reqwest", "helix"]
123+
124+
125+
# [[example]]
126+
# name = "get_moderation"
127+
# path = "examples/get_moderation.rs"
128+
# required-features = ["reqwest", "helix"]
129+
130+
# [[example]]
131+
# name = "get_streams_and_chatters"
132+
# path = "examples/get_streams_and_chatters.rs"
133+
# required-features = ["reqwest", "helix", "tmi"]
134+
135+
# [[example]]
136+
# name = "modify_channel"
137+
# path = "examples/modify_channel.rs"
138+
139+
# required-features = ["reqwest", "helix"]
140+
# [[example]]
141+
# name = "client"
142+
# path = "examples/client.rs"
143+
# required-features = ["reqwest", "helix"]
144+
145+
# [[example]]
146+
# name = "channel_information"
147+
# path = "examples/channel_information.rs"
148+
# required-features = ["reqwest", "helix"]
149+
150+
# [[example]]
151+
# name = "channel_information_custom"
152+
# path = "examples/channel_information_custom.rs"
153+
# required-features = ["reqwest", "helix", "unsupported"]
154+
155+
# [[example]]
156+
# name = "followed_streams"
157+
# path = "examples/followed_streams.rs"
158+
# required-features = ["reqwest", "helix"]
159+
160+
# [[example]]
161+
# name = "mock_api"
162+
# path = "examples/mock_api.rs"
163+
# required-features = ["reqwest", "helix", "mock_api", "twitch_oauth2/mock_api"]
164164

165165
[package.metadata.docs.rs]
166166
features = ["all", "unsupported", "_all"]

src/helix/client.rs

Lines changed: 25 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -113,17 +113,20 @@ impl<'a, C: crate::HttpClient<'a>> HelixClient<'a, C> {
113113
/// # }
114114
/// # // fn main() {run()}
115115
/// ```
116-
pub async fn req_get<R, D, T>(
116+
pub async fn req_get<R, T, D>(
117117
&'a self,
118118
request: R,
119119
token: &T,
120120
) -> Result<
121-
Response<R, yoke::Yoke<D, std::rc::Rc<[u8]>>>,
121+
Response<R, yoke::Yoke<D, Vec<u8>>>,
122122
ClientRequestError<<C as crate::HttpClient<'a>>::Error>,
123123
>
124124
where
125-
R: for <'y> Request<Response<'y> = D> + Request + RequestGet,
126-
D: for<'b> serde::de::Deserialize<'b> + for<'b> yoke::Yokeable<'b, Output = D> + PartialEq,
125+
R: Request<Response = D> + RequestGet,
126+
for<'y> D: yoke::Yokeable<'y>,
127+
//for<'d> yoke::trait_hack::YokeTraitHack<<D as yoke::Yokeable<'d>>::Output>:
128+
// serde::Deserialize<'d>,
129+
for<'d> yoke::trait_hack::YokeTraitHack<<D as yoke::Yokeable<'d>>::Output>: serde::Deserialize<'d>,
127130
T: TwitchToken + ?Sized,
128131
C: Send,
129132
{
@@ -137,33 +140,28 @@ impl<'a, C: crate::HttpClient<'a>> HelixClient<'a, C> {
137140
.into_response_vec()
138141
.await?;
139142
let (parts, body) = response.into_parts();
140-
let body: std::rc::Rc<[u8]> = body.into();
141143
let mut pagination = None;
142144
let mut request_opt = None;
143145
let mut total = None;
144146
let mut other = None;
145-
let resp: yoke::Yoke<<R as Request>::Response<'static>, _> =
146-
yoke::Yoke::try_attach_to_cart(
147-
body,
148-
|body| -> Result<
149-
<D as yoke::Yokeable<'_>>::Output,
150-
ClientRequestError<<C as crate::HttpClient<'a>>::Error>,
151-
> {
152-
let response = http::Response::from_parts(parts, body);
153-
let Response {
154-
data,
155-
pagination: pagination_inner,
156-
request: request_inner,
157-
total: total_inner,
158-
other: other_inner,
159-
} = <R>::parse_response(Some(request), &uri, &response)?;
160-
pagination = pagination_inner;
161-
request_opt = request_inner;
162-
total = total_inner;
163-
other = other_inner;
164-
Ok(data)
165-
},
166-
)?;
147+
let resp: yoke::Yoke<D, _> = yoke::Yoke::try_attach_to_cart(
148+
body,
149+
|body| -> Result<_, ClientRequestError<<C as crate::HttpClient<'a>>::Error>> {
150+
let response = http::Response::from_parts(parts, body);
151+
let Response {
152+
data,
153+
pagination: pagination_inner,
154+
request: request_inner,
155+
total: total_inner,
156+
other: other_inner,
157+
} = <R>::parse_response(Some(request), &uri, &response)?;
158+
pagination = pagination_inner;
159+
request_opt = request_inner;
160+
total = total_inner;
161+
other = other_inner;
162+
Ok(data)
163+
},
164+
)?;
167165

168166
Ok(Response {
169167
data: resp,

src/helix/client/client_ext.rs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
//! Convenience functions for [HelixClient]
2-
3-
use std::borrow::Cow;
4-
52
use crate::helix::{self, ClientRequestError, HelixClient};
63
use crate::types;
74
use twitch_oauth2::TwitchToken;
@@ -28,19 +25,18 @@ impl<'client, C: crate::HttpClient<'client> + Sync> HelixClient<'client, C> {
2825
// .map(|response| response.first())
2926
// }
3027

31-
/// Get [User](helix::users::User) from user id
28+
/// Get [User](helix::users::User) from user id
3229
pub async fn get_user_from_id<T>(
3330
&'client self,
3431
id: impl Into<&types::UserIdRef>,
3532
token: &T,
36-
) -> Result<Option<yoke::Yoke<helix::users::User<'static>, std::rc::Rc<[u8]>>>, ClientError<'client, C>>
33+
) -> Result<Option<yoke::Yoke<helix::users::User<'static>, Vec<u8>>>, ClientError<'client, C>>
3734
where
3835
T: TwitchToken + ?Sized,
3936
{
40-
// self.req_get(helix::users::GetUsersRequest::ids(&[id.into()][..]), token)
41-
// .await
42-
// .map(|response| response.first_yoke())
43-
todo!()
37+
self.req_get(helix::users::GetUsersRequest::ids(&[id.into()][..]), token)
38+
.await
39+
.map(|response| response.first())
4440
}
4541

4642
// /// Get multiple [User](helix::users::User)s from user ids.

src/helix/endpoints/users/get_users.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,31 +105,35 @@ impl<'a> GetUsersRequest<'a> {
105105
/// Return Values for [Get Users](super::get_users)
106106
///
107107
/// [`get-users`](https://dev.twitch.tv/docs/api/reference#get-users)
108-
#[derive(PartialEq, Eq, Deserialize, Serialize, Debug, Clone)]
109-
#[derive(yoke::Yokeable)]
108+
#[derive(PartialEq, Eq, Deserialize, Serialize, Debug, Clone, yoke::Yokeable)]
110109
#[cfg_attr(feature = "deny_unknown_fields", serde(deny_unknown_fields))]
111110
#[non_exhaustive]
112111
pub struct User<'a> {
113112
/// User’s broadcaster type: "partner", "affiliate", or "".
114113
pub broadcaster_type: Option<types::BroadcasterType>,
115114
/// Date when the user was created.
115+
#[serde(borrow = "'a")]
116116
pub created_at: Cow<'a, types::Timestamp>,
117117
/// User’s channel description.
118118
pub description: Option<String>,
119119
/// User’s display name.
120+
#[serde(borrow = "'a")]
120121
pub display_name: Cow<'a, types::DisplayName>,
121122
/// User’s email address. Returned if the request includes the [`user:read:email` scope](twitch_oauth2::Scope::UserReadEmail).
122123
pub email: Option<String>,
123124
/// User’s ID.
125+
#[serde(borrow = "'a")]
124126
pub id: Cow<'a, types::UserId>,
125127
/// User’s login name.
128+
#[serde(borrow = "'a")]
126129
pub login: Cow<'a, types::UserName>,
127130
/// URL of the user’s offline image.
128131
pub offline_image_url: Option<String>,
129132
/// URL of the user’s profile image.
130133
pub profile_image_url: Option<String>,
131134
/// User’s type: "staff", "admin", "global_mod", or "".
132135
#[serde(rename = "type")]
136+
#[serde(borrow = "'a")]
133137
pub type_: Option<Cow<'a, types::UserType>>,
134138
#[deprecated(
135139
since = "0.7.0",
@@ -141,7 +145,7 @@ pub struct User<'a> {
141145
}
142146

143147
impl Request for GetUsersRequest<'_> {
144-
type Response<'a> = Vec<User<'a>>;
148+
type Response = Vec<User<'static>>;
145149

146150
#[cfg(feature = "twitch_oauth2")]
147151
const OPT_SCOPE: &'static [twitch_oauth2::Scope] = &[twitch_oauth2::Scope::UserReadEmail];
@@ -183,13 +187,13 @@ fn test_request() {
183187
"#
184188
.to_vec();
185189

186-
let http_response = http::Response::builder().body(data).unwrap();
190+
let http_response = http::Response::builder().body(data.as_slice()).unwrap();
187191

188192
let uri = req.get_uri().unwrap();
189193
assert_eq!(
190194
uri.to_string(),
191195
"https://api.twitch.tv/helix/users?id=44322889"
192196
);
193197

194-
dbg!(GetUsersRequest::parse_response(Some(req), &uri, http_response).unwrap());
198+
dbg!(GetUsersRequest::parse_response(Some(req), &uri, &http_response).unwrap());
195199
}

src/helix/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ pub use request::{Request, RequestGet}; /* RequestDelete, RequestPatch, RequestP
6060
pub use response::Response;
6161

6262
pub(crate) mod ser;
63-
pub(crate) use crate::deserialize_default_from_null;
64-
use crate::parse_json;
63+
//pub(crate) use crate::deserialize_default_from_null;
64+
//use crate::parse_json;
6565

6666
#[derive(PartialEq, Deserialize, Debug)]
6767
struct InnerResponse<D> {

src/helix/request.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use std::{convert::TryInto, str::FromStr};
44

55
use crate::parse_json;
66

7-
use super::{ser, HelixRequestBody, HelixRequestError, InnerResponse, Response};
7+
use super::{ser, /* HelixRequestBody , */ HelixRequestError, InnerResponse, Response};
88
use errors::*;
99
/// A request is a Twitch endpoint, see [New Twitch API](https://dev.twitch.tv/docs/api/reference) reference
1010
#[async_trait::async_trait]
@@ -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;
21+
type Response;
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.
@@ -357,7 +357,8 @@ pub trait Request: serde::Serialize {
357357
// }
358358

359359
/// Helix endpoint GETs information
360-
pub trait RequestGet: Request {
360+
pub trait RequestGet: Request
361+
where Self::Response: for<'y> yoke::Yokeable<'y> {
361362
/// Create a [`http::Request`] from this [`Request`] in your client
362363
fn create_request(
363364
&self,
@@ -389,9 +390,11 @@ pub trait RequestGet: Request {
389390
request: Option<Self>,
390391
uri: &http::Uri,
391392
response: &http::Response<&'r [u8]>,
392-
) -> Result<Response<Self, <Self as Request>::Response<'r>>, HelixRequestGetError>
393+
) -> Result<Response<Self, <Self::Response as yoke::Yokeable<'r>>::Output>, HelixRequestGetError>
393394
where
394395
Self: Sized,
396+
for<'y> yoke::trait_hack::YokeTraitHack<<Self::Response as yoke::Yokeable<'y>>::Output>:
397+
serde::Deserialize<'y>,
395398
{
396399
let text = std::str::from_utf8(response.body()).map_err(|e| {
397400
HelixRequestGetError::Utf8Error(response.body().to_vec(), e, uri.clone())
@@ -419,9 +422,11 @@ pub trait RequestGet: Request {
419422
uri: &http::Uri,
420423
response: &'r str,
421424
status: http::StatusCode,
422-
) -> Result<Response<Self, <Self as Request>::Response<'r>>, HelixRequestGetError>
425+
) -> Result<Response<Self, <Self::Response as yoke::Yokeable<'r>>::Output>, HelixRequestGetError>
423426
where
424427
Self: Sized,
428+
yoke::trait_hack::YokeTraitHack<<Self::Response as yoke::Yokeable<'r>>::Output>:
429+
serde::Deserialize<'r>,
425430
{
426431
let response: InnerResponse<_> = parse_json(response, true).map_err(|e| {
427432
HelixRequestGetError::DeserializeError(response.to_string(), e, uri.clone(), status)

src/helix/response.rs

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -85,26 +85,17 @@ where R: Request
8585
}
8686
}
8787

88-
impl<R, D, T> Response<R, D>
88+
impl<R, D, B, IT, T> Response<R, yoke::Yoke<D, B>>
8989
where
9090
R: Request,
91-
D: IntoIterator<Item = T>,
91+
D: for<'y> yoke::Yokeable<'y, Output = IT>,
92+
T: for<'y> yoke::Yokeable<'y>,
93+
IT: for<'y> yoke::Yokeable<'y> + IntoIterator<Item = T>,
9294
{
9395
/// Get first result of this response.
94-
pub fn first(self) -> Option<T> { self.data.into_iter().next() }
95-
}
96-
97-
impl<R, D, B, T> Response<R, yoke::Yoke<D, B>>
98-
where
99-
R: Request,
100-
D: for<'y> yoke::Yokeable<'y>,
101-
for<'y> <D as yoke::Yokeable<'y>>::Output: IntoIterator<Item = T>,
102-
T: for<'y> yoke::Yokeable<'y, Output = T>,
103-
{
104-
/// Get first result of this response.
105-
pub fn first_yoke(self) -> Option<yoke::Yoke<T, B>> {
96+
pub fn first(self) -> Option<yoke::Yoke<T, B>> {
10697
self.data
107-
.try_map_project(|yk, _| yk.into_iter().next().ok_or(()))
98+
.try_map_project(|yk, _| yk.into_iter().next().map(|t| t.transform_owned()).ok_or(()))
10899
.ok()
109100
}
110101
}

0 commit comments

Comments
 (0)