Skip to content

Commit

Permalink
Merge pull request #108 from fredmorcos/remove-enum-utils-and-failure…
Browse files Browse the repository at this point in the history
…-deps

Remove `enum-utils` and `failure` deps
  • Loading branch information
fredmorcos authored Sep 5, 2024
2 parents a5c84bf + d1d0a8e commit 917f33c
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 77 deletions.
74 changes: 9 additions & 65 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ flate2 = "1.0"
humantime = "2.1"
parking_lot = "0.12"
log = "0.4"
enum-utils = "0.1"
url = "2.2"
thiserror = "1.0"

Expand Down
48 changes: 41 additions & 7 deletions lib/src/imdb/genre.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#![warn(clippy::all)]

use derive_more::Display;
use enum_utils::FromStr;
use serde::ser::SerializeSeq;
use serde::{Serialize, Serializer};
use std::fmt;
use std::str::FromStr;

/// 27 genres a title can be associated with
#[derive(Debug, Display, FromStr, PartialEq, Eq, Hash, Clone, Copy, Serialize)]
#[derive(Debug, Display, PartialEq, Eq, Hash, Clone, Copy, Serialize)]
#[display(fmt = "{}")]
pub enum Genre {
/// Action
Expand All @@ -34,12 +34,10 @@ pub enum Genre {
Fantasy = 10,
/// FilmNoir
#[display(fmt = "Film-Noir")]
#[enumeration(rename = "Film-Noir")]
#[serde(rename(serialize = "Film-Noir"))]
FilmNoir = 11,
/// GameShow
#[display(fmt = "Game-Show")]
#[enumeration(rename = "Game-Show")]
#[serde(rename(serialize = "Game-Show"))]
GameShow = 12,
/// History
Expand All @@ -56,14 +54,12 @@ pub enum Genre {
News = 18,
/// RealityTv
#[display(fmt = "Reality-TV")]
#[enumeration(rename = "Reality-TV")]
#[serde(rename(serialize = "Reality-TV"))]
RealityTv = 19,
/// Romance
Romance = 20,
/// SciFi
#[display(fmt = "Sci-Fi")]
#[enumeration(rename = "Sci-Fi")]
#[serde(rename(serialize = "Sci-Fi"))]
SciFi = 21,
/// Short
Expand All @@ -72,7 +68,6 @@ pub enum Genre {
Sport = 23,
/// TalkShow
#[display(fmt = "Talk-Show")]
#[enumeration(rename = "Talk-Show")]
#[serde(rename(serialize = "Talk-Show"))]
TalkShow = 24,
/// Thriller
Expand All @@ -85,6 +80,45 @@ pub enum Genre {
Experimental = 28,
}

impl FromStr for Genre {
type Err = ();

fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
"Action" => Ok(Genre::Action),
"Adult" => Ok(Genre::Adult),
"Adventure" => Ok(Genre::Adventure),
"Animation" => Ok(Genre::Animation),
"Biography" => Ok(Genre::Biography),
"Comedy" => Ok(Genre::Comedy),
"Crime" => Ok(Genre::Crime),
"Documentary" => Ok(Genre::Documentary),
"Drama" => Ok(Genre::Drama),
"Family" => Ok(Genre::Family),
"Fantasy" => Ok(Genre::Fantasy),
"Film-Noir" => Ok(Genre::FilmNoir),
"Game-Show" => Ok(Genre::GameShow),
"History" => Ok(Genre::History),
"Horror" => Ok(Genre::Horror),
"Music" => Ok(Genre::Music),
"Musical" => Ok(Genre::Musical),
"Mystery" => Ok(Genre::Mystery),
"News" => Ok(Genre::News),
"Reality-TV" => Ok(Genre::RealityTv),
"Romance" => Ok(Genre::Romance),
"Sci-Fi" => Ok(Genre::SciFi),
"Short" => Ok(Genre::Short),
"Sport" => Ok(Genre::Sport),
"Talk-Show" => Ok(Genre::TalkShow),
"Thriller" => Ok(Genre::Thriller),
"War" => Ok(Genre::War),
"Western" => Ok(Genre::Western),
"Experimental" => Ok(Genre::Experimental),
_ => Err(()),
}
}
}

impl Genre {
/// Returns the largest-valued [Genre] enum variant enum as [u8].
pub(crate) const fn max() -> u8 {
Expand Down
29 changes: 25 additions & 4 deletions lib/src/imdb/title_type.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
#![warn(clippy::all)]

use derive_more::Display;
use enum_utils::FromStr;
use serde::Serialize;
use std::hash::Hash;
use std::{hash::Hash, str::FromStr};

/// Encodes the 13 types of a title.
#[derive(Debug, Display, FromStr, PartialEq, Eq, Hash, Clone, Copy, Serialize)]
#[enumeration(rename_all = "camelCase")]
#[derive(Debug, Display, PartialEq, Eq, Hash, Clone, Copy, Serialize)]
#[display(fmt = "{}")]
pub enum TitleType {
// Games
Expand Down Expand Up @@ -54,6 +52,29 @@ pub enum TitleType {
RadioSeries = 12,
}

impl FromStr for TitleType {
type Err = ();

fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
"videoGame" => Ok(TitleType::VideoGame),
"short" => Ok(TitleType::Short),
"video" => Ok(TitleType::Video),
"movie" => Ok(TitleType::Movie),
"tvShort" => Ok(TitleType::TvShort),
"tvMovie" => Ok(TitleType::TvMovie),
"tvSpecial" => Ok(TitleType::TvSpecial),
"tvEpisode" => Ok(TitleType::TvEpisode),
"tvPilot" => Ok(TitleType::TvPilot),
"radioEpisode" => Ok(TitleType::RadioEpisode),
"tvSeries" => Ok(TitleType::TvSeries),
"tvMiniSeries" => Ok(TitleType::TvMiniSeries),
"radioSeries" => Ok(TitleType::RadioSeries),
_ => Err(()),
}
}
}

impl TitleType {
/// Converts a byte representation to its corresponding TitleType.
///
Expand Down

0 comments on commit 917f33c

Please sign in to comment.