From 0e09c2c06fc0b81f11d12985a4172c815233db17 Mon Sep 17 00:00:00 2001 From: David Blajda Date: Wed, 8 May 2019 15:15:42 +0000 Subject: Refactor Ids again and cargo update --- Cargo.toml | 6 ++- src/helix/models.rs | 12 ++--- src/kraken/models.rs | 4 +- src/lib.rs | 2 +- src/types.rs | 125 +++++++++++++-------------------------------------- 5 files changed, 46 insertions(+), 103 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index df46b2a..96cf8e9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,10 +5,14 @@ authors = ["David Blajda "] edition = "2018" [dependencies] -reqwest = "0.9.5" +reqwest = ">=0.9.5" +hyper = "0.12.20" +http = "0.1.15" futures = "0.1.25" tokio = "0.1.13" dotenv = "0.13.0" +log = "0.4.5" +env_logger = "0.6.0" serde = "1.0.81" serde_json = "1.0.33" serde_derive = "1.0.81" diff --git a/src/helix/models.rs b/src/helix/models.rs index e63a9f4..1e9f0ec 100644 --- a/src/helix/models.rs +++ b/src/helix/models.rs @@ -47,8 +47,8 @@ pub struct Cursor { #[derive(Debug, Deserialize, Serialize)] pub struct Video { - pub id: VideoId<'static>, - pub user_id: UserId<'static>, + pub id: VideoId, + pub user_id: UserId, pub user_name: String, pub title: String, pub description: String, @@ -72,7 +72,7 @@ pub struct Video { #[derive(Debug, Deserialize, Serialize)] pub struct User { - pub id: UserId<'static>, + pub id: UserId, 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<'static>, + pub broadcaster_id: ChannelId, pub broadcaster_name: String, - pub creator_id: UserId<'static>, + pub creator_id: UserId, pub creator_name: String, - pub video_id: VideoId<'static>, + pub video_id: VideoId, pub game_id: String, pub language: String, pub title: String, diff --git a/src/kraken/models.rs b/src/kraken/models.rs index 5b8c30b..931f849 100644 --- a/src/kraken/models.rs +++ b/src/kraken/models.rs @@ -63,7 +63,7 @@ pub struct Thumbnails { #[derive(Debug, Deserialize, Serialize)] pub struct UserData { - pub id: UserId<'static>, + pub id: UserId, pub name: String, pub display_name: String, #[serde(with = "url_serde")] @@ -73,7 +73,7 @@ pub struct UserData { #[derive(Debug, Deserialize, Serialize)] pub struct Vod { - pub id: VideoId<'static>, + pub id: VideoId, #[serde(with = "url_serde")] pub url: Url, } diff --git a/src/lib.rs b/src/lib.rs index 38778e2..35361ed 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,5 +1,5 @@ #![recursion_limit="128"] -#![feature(try_from)] +#![feature(never_type)] extern crate futures; extern crate reqwest; extern crate serde; diff --git a/src/types.rs b/src/types.rs index 38ab50c..e8ae2a3 100644 --- a/src/types.rs +++ b/src/types.rs @@ -1,132 +1,99 @@ use std::convert::AsRef; -use std::str::FromStr; use std::cmp::{Eq, PartialEq}; use std::marker::PhantomData; +use std::convert::Into; +use std::fmt; +use std::fmt::{Debug, Formatter}; /* Used for Id's that can be interpreted as integers but aren't returned as * an int by Twitch's API. (Maybe to allow a quick switch to a different representation * without breaking the json schema?) + * + * Don't Implement Display for StringID since it would allow comparisions between + * different StringId types */ pub struct User {} pub struct Video {} pub struct Game {} +pub struct Clip {} -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<'a> = IntegerId<'a, Game>; - - -use std::borrow::Cow; +pub type UserId = StringId; +pub type ChannelId = UserId; +pub type VideoId = StringId