diff options
-rw-r--r-- | src/bin/main.rs | 9 | ||||
-rw-r--r-- | src/client.rs | 1 | ||||
-rw-r--r-- | src/helix/models.rs | 12 | ||||
-rw-r--r-- | src/kraken/models.rs | 4 | ||||
-rw-r--r-- | src/types.rs | 95 |
5 files changed, 63 insertions, 58 deletions
diff --git a/src/bin/main.rs b/src/bin/main.rs index 15b7753..9be688b 100644 --- a/src/bin/main.rs +++ b/src/bin/main.rs @@ -68,6 +68,12 @@ fn main() { () }); + let u = helix_client + .users() + .users(vec!(), vec!("freakey")) + .map(|res| {println!("{:?}", res); ()}) + .map_err(|res| {println!("{:?}", res); ()}); + /* Prevents tokio from **hanging** * since tokio::run blocks the current thread and waits for the entire runtime * to become idle but it will never becomes idle since we keep a reference @@ -75,6 +81,8 @@ fn main() { */ //std::mem::drop(authed_client); tokio::run( + u + /* clip.join(clip2) .and_then(|(c1, c2)| { println!("{:?}", c1); @@ -93,6 +101,7 @@ fn main() { }) .map(|_| ()) .map_err(|_| ()) + */ /*videos*/ ); } diff --git a/src/client.rs b/src/client.rs index 3371670..66f32d6 100644 --- a/src/client.rs +++ b/src/client.rs @@ -882,6 +882,7 @@ impl<T: DeserializeOwned + 'static + Send> Future for ApiRequest<T> { err }) .map(move |mut response| { + println!("{:?}", response); if let Some(key) = key_ok { if let Some(limits) = client_ok.ratelimit(key) { let mut mut_limits = limits.inner.lock().unwrap(); diff --git a/src/helix/models.rs b/src/helix/models.rs index 5a35869..af221bc 100644 --- a/src/helix/models.rs +++ b/src/helix/models.rs @@ -47,8 +47,8 @@ pub struct Cursor { #[derive(Debug, Deserialize)] pub struct Video { - pub id: VideoId, - pub user_id: UserId, + pub id: VideoId<'static>, + pub user_id: UserId<'static>, pub user_name: String, pub title: String, pub description: String, @@ -72,7 +72,7 @@ pub struct Video { #[derive(Debug, Deserialize)] pub struct User { - pub id: UserId, + pub id: UserId<'static>, pub login: String, pub display_name: String, #[serde(rename = "type")] @@ -94,11 +94,11 @@ pub struct Clip { pub url: Url, #[serde(with = "url_serde")] pub embed_url: Url, - pub broadcaster_id: ChannelId, + pub broadcaster_id: ChannelId<'static>, pub broadcaster_name: String, - pub creator_id: UserId, + pub creator_id: UserId<'static>, pub creator_name: String, - pub video_id: VideoId, + pub video_id: VideoId<'static>, pub game_id: String, pub language: String, pub title: String, diff --git a/src/kraken/models.rs b/src/kraken/models.rs index 8b5b6d6..d6a6e4f 100644 --- a/src/kraken/models.rs +++ b/src/kraken/models.rs @@ -45,7 +45,7 @@ pub struct Thumbnails { #[derive(Debug, Deserialize)] pub struct UserData { - pub id: UserId, + pub id: UserId<'static>, pub name: String, pub display_name: String, #[serde(with = "url_serde")] @@ -55,7 +55,7 @@ pub struct UserData { #[derive(Debug, Deserialize)] pub struct Vod { - pub id: VideoId, + pub id: VideoId<'static>, #[serde(with = "url_serde")] pub url: Url, } diff --git a/src/types.rs b/src/types.rs index f59fd3a..eeede15 100644 --- a/src/types.rs +++ b/src/types.rs @@ -1,6 +1,5 @@ use std::convert::AsRef; use std::str::FromStr; -use std::sync::Arc; use std::cmp::{Eq, PartialEq}; use std::marker::PhantomData; @@ -13,109 +12,105 @@ pub struct User {} pub struct Video {} pub struct Game {} -pub type UserId = IntegerId<User>; -pub type ChannelId = UserId; -pub type VideoId = IntegerId<Video>; +pub type UserId<'a> = IntegerId<'a, User>; +pub type ChannelId<'a> = UserId<'a>; +pub type VideoId<'a> = IntegerId<'a, Video>; pub type ClipId = Id; -pub type GameId = IntegerId<Game>; +pub type GameId<'a> = IntegerId<'a, Game>; -#[derive(Clone)] -pub struct IntegerId<T> { - inner: Arc<IntegerIdRef<T>> -} -struct IntegerIdRef<T> { - id: String, +use std::borrow::Cow; + +#[derive(Clone)] +pub struct IntegerId<'a, T> { int: u32, - _type: PhantomData<T> + id: Cow<'a, str>, + marker: PhantomData<T> } -impl<T> IntegerId<T> { - pub fn new(id: u32) -> IntegerId<T> { +impl<T> IntegerId<'static, T> { + pub fn new(id: u32) -> IntegerId<'static, T> { IntegerId { - inner: Arc::new(IntegerIdRef { - id: id.to_string(), - int: id, - _type: PhantomData, - }) + id: Cow::Owned(id.to_string()), + int: id, + marker: PhantomData, } } } -impl<T> AsRef<u32> for IntegerId<T> { - fn as_ref(&self) -> &u32 { - &self.inner.int +impl<'a, T> IntegerId<'a, T> { + + pub fn from_str(id: &'a str) + -> Result<IntegerId<'a, T>, std::num::ParseIntError> + { + let int = id.parse::<u32>()?; + Ok(IntegerId { + id: Cow::Borrowed(id), + int, + marker: PhantomData, + }) } } -impl<T> AsRef<str> for IntegerId<T> { +impl<'a, T> AsRef<str> for IntegerId<'a, T> { fn as_ref(&self) -> &str { - &self.inner.id + &self.id } } use std::convert::Into; -impl<T> Into<u32> for &IntegerId<T> { +impl<'a, T> Into<u32> for &'a IntegerId<'a, T> { fn into(self) -> u32 { - self.inner.int + self.int } } -impl<'a, T> Into<&'a str> for &'a IntegerId<T> { +impl<'a, T> Into<&'a str> for &'a IntegerId<'a, T> { fn into(self) -> &'a str { - &self.inner.id + &self.id } } use std::fmt; use std::fmt::{Display, Debug, Formatter}; -impl<T> Display for IntegerId<T> { +impl<'a, T> Display for IntegerId<'a, T> { fn fmt(&self, f: &mut Formatter) -> fmt::Result { - write!(f, "{}", &self.inner.id) + write!(f, "{}", &self.id) } } -impl<T> Debug for IntegerId<T> { +impl<'a, T> Debug for IntegerId<'a, T> { fn fmt(&self, f: &mut Formatter) -> fmt::Result { - write!(f, "{:?}", &self.inner.id) + write!(f, "{:?}", &self.id) } } -impl<T> PartialEq<IntegerId<T>> for IntegerId<T> { +impl<'a, 'b, T> PartialEq<IntegerId<'a, T>> for IntegerId<'b, T> { fn eq(&self, other: &IntegerId<T>) -> bool { - self.inner.int == other.inner.int + self.int == other.int } } -impl<T> Eq for IntegerId<T> {} +impl<'a, T> Eq for IntegerId<'a, T> {} -impl<T> PartialEq<&str> for IntegerId<T> { - fn eq(&self, other: &&str) -> bool { - self.inner.id == *other +impl<'a, T> PartialEq<str> for IntegerId<'a, T> { + fn eq(&self, other: &str) -> bool { + self.id == *other } } -impl<T> PartialEq<u32> for IntegerId<T> { +impl<'a, T> PartialEq<u32> for IntegerId<'a, T> { fn eq(&self, other: &u32) -> bool { - self.inner.int == *other - } -} - - -impl<T> FromStr for IntegerId<T> { - type Err = std::num::ParseIntError; - fn from_str(s: &str) -> Result<Self, Self::Err> { - let int = u32::from_str(s)?; - Ok(IntegerId::new(int)) + self.int == *other } } use serde::{Deserialize, Deserializer}; -impl<'de, T> Deserialize<'de> for IntegerId<T> { +impl<'de, T> Deserialize<'de> for IntegerId<'static, T> { fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: Deserializer<'de> |