summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Cargo.toml6
-rw-r--r--src/helix/models.rs12
-rw-r--r--src/kraken/models.rs4
-rw-r--r--src/lib.rs2
-rw-r--r--src/types.rs125
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 <blajda@hotmail.com>"]
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<User>;
+pub type ChannelId = UserId;
+pub type VideoId = StringId<Video>;
+pub type ClipId = StringId<Clip>;
+pub type GameId = StringId<Game>;
#[derive(Clone)]
-pub struct IntegerId<'a, T> {
- pub int: u32,
- id: Cow<'a, str>,
+pub struct StringId<T> {
+ id: String,
marker: PhantomData<T>
}
-impl<T> IntegerId<'static, T> {
- pub fn new(id: u32) -> IntegerId<'static, T> {
- IntegerId {
- id: Cow::Owned(id.to_string()),
- int: id,
+impl<T> StringId<T> {
+ pub fn new(id: String) -> StringId<T> {
+ StringId {
+ id: id,
marker: PhantomData,
}
}
}
-impl<'a, T> IntegerId<'a, T> {
+impl<'a, T> StringId<T> {
pub fn from_str(id: &'a str)
- -> Result<IntegerId<'a, T>, std::num::ParseIntError>
+ -> Result<StringId<T>, !>
{
- let int = id.parse::<u32>()?;
- Ok(IntegerId {
- id: Cow::Borrowed(id),
- int,
- marker: PhantomData,
- })
+ Ok(StringId::new(id.to_owned()))
}
}
-impl<'a, T> AsRef<str> for IntegerId<'a, T> {
+impl<'a, T> AsRef<str> for StringId<T> {
fn as_ref(&self) -> &str {
&self.id
}
}
-use std::convert::Into;
-
-/*
-impl<'a, T> Into<u32> for &'a IntegerId<'a, T> {
- fn into(self) -> u32 {
- self.int
- }
-}
-*/
-impl<'a, T> Into<&'a str> for &'a IntegerId<'a, T> {
+impl<'a, T> Into<&'a str> for &'a StringId<T> {
fn into(self) -> &'a str {
&self.id
}
}
-use std::fmt;
-use std::fmt::{Display, Debug, Formatter};
-
-impl<'a, T> Display for IntegerId<'a, T> {
-
- fn fmt(&self, f: &mut Formatter) -> fmt::Result
- {
- write!(f, "{}", &self.id)
- }
-}
-
-impl<'a, T> Debug for IntegerId<'a, T> {
+impl<T> Debug for StringId<T> {
fn fmt(&self, f: &mut Formatter) -> fmt::Result
{
write!(f, "{:?}", &self.id)
}
}
-impl<'a, 'b, T> PartialEq<IntegerId<'a, T>> for IntegerId<'b, T> {
- fn eq(&self, other: &IntegerId<T>) -> bool {
- self.int == other.int
+impl<T> PartialEq<StringId<T>> for StringId<T> {
+ fn eq(&self, other: &StringId<T>) -> bool {
+ self.id == other.id
}
}
-impl<'a, T> Eq for IntegerId<'a, T> {}
+impl<T> Eq for StringId<T> {}
-impl<'a, T> PartialEq<str> for IntegerId<'a, T> {
+impl<T> PartialEq<str> for StringId<T> {
fn eq(&self, other: &str) -> bool {
self.id.eq(other)
}
}
-/*
-impl<'a, T> PartialEq<u32> for IntegerId<'a, T> {
- fn eq(&self, other: &u32) -> bool {
- self.int == *other
- }
-}
-*/
-
use serde::{Deserialize, Deserializer};
-impl<'de, T> Deserialize<'de> for IntegerId<'static, T> {
+impl<'de, T> Deserialize<'de> for StringId<T> {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where D: Deserializer<'de>
{
let id = String::deserialize(deserializer)?;
- let int = (&id).parse::<u32>().map_err(serde::de::Error::custom)?;
- Ok(IntegerId::new(int))
+ Ok(StringId::new(id))
}
}
use serde::{Serialize, Serializer};
-impl<'a, T> Serialize for IntegerId<'a, T> {
+impl<'a, T> Serialize for StringId<T> {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
@@ -135,32 +102,6 @@ impl<'a, T> Serialize for IntegerId<'a, T> {
}
}
-pub struct Id {
- inner: String
-}
-
-impl Id {
- pub fn new(id: &str) -> Id {
- Id {
- inner: id.to_owned(),
- }
- }
-}
-
-impl Display for Id {
-
- fn fmt(&self, f: &mut Formatter) -> fmt::Result
- {
- write!(f, "{}", &self.inner)
- }
-}
-impl AsRef<str> for Id {
-
- fn as_ref(&self) -> &str {
- &self.inner
- }
-}
-
#[cfg(test)]
mod tests {
use super::{UserId, VideoId};
@@ -177,12 +118,10 @@ mod tests {
let u2 = u2.unwrap();
assert_eq!(u1, u2);
- //assert_eq!(u1, 1234);
assert_eq!(&u1, "1234");
let u2 = UserId::from_str("1235").unwrap();
assert_ne!(u1, u2);
- //assert_ne!(u1, 1235);
assert_ne!(&u1, "1235");
/* This must give a compile error */