From 6bb02b1e8d037fbd9f3d448a98f0e2d734ee02b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emil=20Gardstr=C3=B6m?= Date: Sun, 18 Sep 2022 12:45:14 +0200 Subject: [PATCH] nope --- Cargo.lock | 1 + Cargo.toml | 1 + src/helix/client.rs | 12 ++++++------ src/helix/endpoints/users/get_users.rs | 5 ++++- src/helix/request.rs | 2 ++ 5 files changed, 14 insertions(+), 7 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 9f2d497fe9..6be4ab3bc3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2069,6 +2069,7 @@ dependencies = [ "url", "version_check", "yoke", + "zerofrom", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index a5cf40c50f..258371acfb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -51,6 +51,7 @@ futures = { version = "0.3.16", optional = true } hyper = { version = "0.14.18", optional = true } twitch_types = { version = "0.2.0", path = "./twitch_types" } yoke = { version = "0.6.1", features = ["serde", "derive"] } +zerofrom = { version = "0.1.1", features = ["derive"] } [features] default = [] diff --git a/src/helix/client.rs b/src/helix/client.rs index 5f491753e3..1839dbad2b 100644 --- a/src/helix/client.rs +++ b/src/helix/client.rs @@ -101,17 +101,17 @@ impl<'a, C: crate::HttpClient<'a>> HelixClient<'a, C> { /// # } /// # // fn main() {run()} /// ``` - pub async fn req_get( + pub async fn req_get<'d, R, D, T>( &'a self, request: R, token: &T, ) -> Result< - Response>>, + Response::ResponseOwned, std::rc::Rc<[u8]>>>, ClientRequestError<>::Error>, > where - for<'r> R: RequestGet = D2> + Request = D2>, - for<'d> D: yoke::Yokeable<'d, Output = D2> + 'static, + R: RequestGet = D> + Request = D>, + ::ResponseOwned: for<'y> yoke::Yokeable<'y, Output = D>, T: TwitchToken + ?Sized, C: Send, { @@ -130,9 +130,9 @@ impl<'a, C: crate::HttpClient<'a>> HelixClient<'a, C> { let mut request_opt = None; let mut total = None; let mut other = None; - let resp: yoke::Yoke = yoke::Yoke::try_attach_to_cart( + let resp: yoke::Yoke<_, _> = yoke::Yoke::try_attach_to_cart( body, - |body| -> Result<_, ClientRequestError<>::Error>> { + |body: &[u8]| -> Result<_, ClientRequestError<>::Error>> { let response = http::Response::from_parts(parts, body); let Response { data, diff --git a/src/helix/endpoints/users/get_users.rs b/src/helix/endpoints/users/get_users.rs index 74709475f7..a2be78ba03 100644 --- a/src/helix/endpoints/users/get_users.rs +++ b/src/helix/endpoints/users/get_users.rs @@ -59,11 +59,12 @@ pub struct GetUsersRequest { /// Return Values for [Get Users](super::get_users) /// /// [`get-users`](https://dev.twitch.tv/docs/api/reference#get-users) -#[derive(PartialEq, Deserialize, Serialize, Debug, Clone, yoke::Yokeable)] +#[derive(PartialEq, Deserialize, Serialize, Debug, Clone, yoke::Yokeable, zerofrom::ZeroFrom)] #[cfg_attr(feature = "deny_unknown_fields", serde(deny_unknown_fields))] #[non_exhaustive] pub struct User<'a> { /// User’s broadcaster type: "partner", "affiliate", or "". + #[zerofrom(clone)] pub broadcaster_type: Option, /// Date when the user was created. pub created_at: Cow<'a, types::TimestampRef>, @@ -83,6 +84,7 @@ pub struct User<'a> { pub profile_image_url: Option>, /// User’s type: "staff", "admin", "global_mod", or "". #[serde(rename = "type")] + #[zerofrom(clone)] pub type_: Option, #[deprecated( since = "0.7.0", @@ -95,6 +97,7 @@ pub struct User<'a> { impl Request for GetUsersRequest { type Response<'a> = Vec>; + type ResponseOwned = Vec>; #[cfg(feature = "twitch_oauth2")] const OPT_SCOPE: &'static [twitch_oauth2::Scope] = &[twitch_oauth2::Scope::UserReadEmail]; diff --git a/src/helix/request.rs b/src/helix/request.rs index e53ec1c858..feb817f596 100644 --- a/src/helix/request.rs +++ b/src/helix/request.rs @@ -19,6 +19,8 @@ pub trait Request: serde::Serialize { const OPT_SCOPE: &'static [twitch_oauth2::Scope] = &[]; /// Response type. twitch's response will deserialize to this. type Response<'a>: for<'de> serde::de::Deserialize<'de> + PartialEq; + /// Owned response + type ResponseOwned; /// Defines layout of the url parameters. fn query(&self) -> Result { ser::to_string(&self) } /// Returns full URI for the request, including query parameters.