Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

decouple serde_derive and serde #50

Merged
merged 3 commits into from
Sep 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@

## [Unreleased] - ReleaseDate

[Commits](https://github.com/twitch-rs/twitch_types/compare/v0.4.2...Unreleased)
[Commits](https://github.com/twitch-rs/twitch_types/compare/v0.4.3...Unreleased)

## [v0.4.3] - 2023-09-17

[Commits](https://github.com/twitch-rs/twitch_types/compare/v0.4.2...v0.4.3)

## [v0.4.2] - 2023-07-16

Expand Down
3 changes: 2 additions & 1 deletion Cargo.lock

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

21 changes: 11 additions & 10 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "twitch_types"
version = "0.4.2"
version = "0.4.3"
edition = "2021"
repository = "https://github.com/twitch-rs/twitch_types"
license = "MIT OR Apache-2.0"
Expand All @@ -20,7 +20,8 @@ rust-version = "1.63.0"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
serde = { version = "1.0", features = ["derive"], optional = true }
serde = { version = "1.0", optional = true }
serde_derive = { version = "1.0", optional = true }
time = { version = "0.3", optional = true, default-features = false, features = [
"parsing",
"formatting",
Expand All @@ -33,17 +34,17 @@ zerofrom = { version = "0.1.0", optional = true }
[features]
default = []

emote = ["serde?/derive"]
moderation = ["serde?/derive"]
points = ["serde?/derive"]
stream = ["serde?/derive"]
emote = ["serde"]
moderation = ["serde"]
points = ["serde"]
stream = ["serde"]
timestamp = []
user = ["serde?/derive"]
goal = ["serde?/derive"]
user = ["serde"]
goal = ["serde"]
eventsub = []
color = ["serde/derive"]
color = ["serde"]

serde = ["dep:serde"]
serde = ["dep:serde", "dep:serde_derive"]

deny_unknown_fields = ["serde"]

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Twitch Types | Rust library for common types used in Twitch

[![github]](https://github.com/twitch-rs/twitch_types) [![crates-io]](https://crates.io/crates/twitch_types) [![docs-rs-big]](https://docs.rs/twitch_types/0.4.2/twitch_types)
[![github]](https://github.com/twitch-rs/twitch_types) [![crates-io]](https://crates.io/crates/twitch_types) [![docs-rs-big]](https://docs.rs/twitch_types/0.4.3/twitch_types)

[github]: https://img.shields.io/badge/github-twitch--rs/twitch__types-8da0cb?style=for-the-badge&labelColor=555555&logo=github
[crates-io]: https://img.shields.io/crates/v/twitch_types.svg?style=for-the-badge&color=fc8d62&logo=rust
Expand Down
9 changes: 5 additions & 4 deletions release.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
pre-release-commit-message = "release {{crate_name}} {{version}}"
tag = false
push = false
publish = false
enable-features = ["all", "twitch_oauth2/all", "unsupported"]
disable-tag = true
disable-push = true
disable-publish = true
no-dev-version = true
enable-all-features = true
consolidate-commits = false
pre-release-replacements = [
{file="CHANGELOG.md", search="Unreleased", replace="v{{version}}", prerelease=false},
Expand Down
4 changes: 2 additions & 2 deletions src/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ impl_extra!(MsgId, MsgIdRef);

/// Broadcaster types: "partner", "affiliate", or "".
#[derive(Copy, Clone, Default, Debug, PartialEq, PartialOrd, Eq, Ord, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize))]
#[cfg_attr(feature = "serde", derive(serde_derive::Deserialize))]
pub enum BroadcasterType {
/// Partner
#[cfg_attr(feature = "serde", serde(rename = "partner"))]
Expand Down Expand Up @@ -62,7 +62,7 @@ impl serde::Serialize for BroadcasterType {

/// User types: "staff", "admin", "global_mod", or "".
#[derive(Copy, Clone, Default, Debug, PartialEq, PartialOrd, Eq, Ord, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize))]
#[cfg_attr(feature = "serde", derive(serde_derive::Deserialize))]

pub enum UserType {
/// Staff
Expand Down
2 changes: 1 addition & 1 deletion src/color.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ impl<'a> arbitrary::Arbitrary<'a> for HexColor {
}

/// Colors a user can have
#[derive(Debug, PartialEq, Eq, Clone, Deserialize)]
#[derive(Debug, PartialEq, Eq, Clone, serde_derive::Deserialize)]
#[serde(field_identifier, rename_all = "snake_case")]
pub enum NamedUserColor<'a> {
/// Blue
Expand Down
28 changes: 20 additions & 8 deletions src/emote.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};

manual_braid! {
/// A Badge set ID
pub struct BadgeSetId;
Expand Down Expand Up @@ -47,7 +44,10 @@ pub(crate) static EMOTE_V2_URL_TEMPLATE: &str =

/// Formats for an emote.
#[derive(Debug, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(
feature = "serde",
derive(serde_derive::Serialize, serde_derive::Deserialize)
)]
#[cfg_attr(feature = "serde", serde(rename_all = "lowercase"))]
pub enum EmoteAnimationSetting {
/// Static
Expand All @@ -67,7 +67,10 @@ impl std::fmt::Display for EmoteAnimationSetting {

/// Background themes available for an emote.
#[derive(Debug, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(
feature = "serde",
derive(serde_derive::Serialize, serde_derive::Deserialize)
)]
#[cfg_attr(feature = "serde", serde(rename_all = "lowercase"))]
pub enum EmoteThemeMode {
/// Light
Expand All @@ -91,7 +94,10 @@ impl std::fmt::Display for EmoteThemeMode {

/// Scales available for an emote.
#[derive(Debug, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(
feature = "serde",
derive(serde_derive::Serialize, serde_derive::Deserialize)
)]
pub enum EmoteScale {
/// 1.0
#[cfg_attr(feature = "serde", serde(rename = "1.0"))]
Expand Down Expand Up @@ -248,7 +254,10 @@ impl_extra!(EmoteSetId, EmoteSetIdRef);

/// An emote index as defined by eventsub, similar to IRC `emotes` twitch tag.
#[derive(PartialEq, Eq, Debug, Clone)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(
feature = "serde",
derive(serde_derive::Serialize, serde_derive::Deserialize)
)]
#[cfg_attr(feature = "deny_unknown_fields", serde(deny_unknown_fields))]
#[non_exhaustive]
pub struct ResubscriptionEmote {
Expand All @@ -268,7 +277,10 @@ impl std::fmt::Display for ResubscriptionEmote {

/// Links to the same image of different sizes
#[derive(Clone, Debug, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(
feature = "serde",
derive(serde_derive::Serialize, serde_derive::Deserialize)
)]
#[cfg_attr(feature = "deny_unknown_fields", serde(deny_unknown_fields))]
#[non_exhaustive]
pub struct Image {
Expand Down
8 changes: 4 additions & 4 deletions src/goal.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};

manual_braid! {
/// A Creator Goal ID
pub struct CreatorGoalId;
Expand All @@ -10,7 +7,10 @@ impl_extra!(CreatorGoalId, CreatorGoalIdRef);

/// Type of creator goal
#[derive(PartialEq, Eq, Debug, Clone)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(
feature = "serde",
derive(serde_derive::Serialize, serde_derive::Deserialize)
)]
#[cfg_attr(feature = "serde", serde(rename_all = "snake_case"))]
#[non_exhaustive]
pub enum CreatorGoalType {
Expand Down
8 changes: 4 additions & 4 deletions src/moderation.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};

manual_braid! {
/// A blocked term ID
pub struct BlockedTermId;
Expand All @@ -10,7 +7,10 @@ impl_extra!(BlockedTermId, BlockedTermIdRef);

/// Status of a message that is or was in AutoMod queue
#[derive(PartialEq, Eq, Debug, Clone)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(
feature = "serde",
derive(serde_derive::Serialize, serde_derive::Deserialize)
)]
#[cfg_attr(feature = "deny_unknown_fields", serde(deny_unknown_fields))]
#[cfg_attr(feature = "serde", serde(rename_all = "UPPERCASE"))]
#[non_exhaustive]
Expand Down
38 changes: 28 additions & 10 deletions src/points.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};

use crate::{DisplayName, UserId, UserName};
manual_braid! {
/// A reward ID.
Expand Down Expand Up @@ -46,7 +43,10 @@ impl_extra!(PredictionOutcomeId, PredictionOutcomeIdRef);

/// Reward redemption max
#[derive(Clone, Debug, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(
feature = "serde",
derive(serde_derive::Serialize, serde_derive::Deserialize)
)]
#[cfg_attr(feature = "deny_unknown_fields", serde(deny_unknown_fields))]
#[cfg_attr(feature = "serde", serde(untagged))]
#[non_exhaustive]
Expand All @@ -71,7 +71,10 @@ pub enum Max {

/// Information about global cooldown
#[derive(Clone, Debug, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(
feature = "serde",
derive(serde_derive::Serialize, serde_derive::Deserialize)
)]
#[cfg_attr(feature = "deny_unknown_fields", serde(deny_unknown_fields))]
#[non_exhaustive]
pub struct GlobalCooldown {
Expand All @@ -84,7 +87,10 @@ pub struct GlobalCooldown {

/// Poll choice
#[derive(Clone, Debug, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(
feature = "serde",
derive(serde_derive::Serialize, serde_derive::Deserialize)
)]
#[cfg_attr(feature = "deny_unknown_fields", serde(deny_unknown_fields))]
#[non_exhaustive]
pub struct PollChoice {
Expand All @@ -103,7 +109,10 @@ pub struct PollChoice {
// FIXME: Poll status has different name depending on if returned from helix or eventsub. See https://twitch.uservoice.com/forums/310213-developers/suggestions/43402176
/// Status of a poll
#[derive(PartialEq, Eq, Debug, Clone)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(
feature = "serde",
derive(serde_derive::Serialize, serde_derive::Deserialize)
)]
#[cfg_attr(feature = "deny_unknown_fields", serde(deny_unknown_fields))]
#[cfg_attr(feature = "serde", serde(rename_all = "UPPERCASE"))]
#[non_exhaustive]
Expand Down Expand Up @@ -131,7 +140,10 @@ pub enum PollStatus {
// FIXME: Prediction status has different name depending on if returned from helix or eventsub. See https://twitch.uservoice.com/forums/310213-developers/suggestions/43402197
/// Status of the Prediction
#[derive(PartialEq, Eq, Debug, Clone)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(
feature = "serde",
derive(serde_derive::Serialize, serde_derive::Deserialize)
)]
#[cfg_attr(feature = "deny_unknown_fields", serde(deny_unknown_fields))]
#[cfg_attr(feature = "serde", serde(rename_all = "UPPERCASE"))]
#[non_exhaustive]
Expand All @@ -152,7 +164,10 @@ pub enum PredictionStatus {

/// Outcome for the Prediction
#[derive(PartialEq, Eq, Debug, Clone)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(
feature = "serde",
derive(serde_derive::Serialize, serde_derive::Deserialize)
)]
#[cfg_attr(feature = "deny_unknown_fields", serde(deny_unknown_fields))]
#[non_exhaustive]
pub struct PredictionOutcome {
Expand All @@ -173,7 +188,10 @@ pub struct PredictionOutcome {
// FIXME: eventsub adds prefix `user_*`. See https://discord.com/channels/325552783787032576/326772207844065290/842359030252437514
/// Users who were the top predictors.
#[derive(PartialEq, Eq, Debug, Clone)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(
feature = "serde",
derive(serde_derive::Serialize, serde_derive::Deserialize)
)]
#[cfg_attr(feature = "deny_unknown_fields", serde(deny_unknown_fields))]
#[non_exhaustive]
pub struct PredictionTopPredictors {
Expand Down
26 changes: 19 additions & 7 deletions src/stream.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};
use serde::Serialize;

manual_braid! {
/// A Stream ID
Expand Down Expand Up @@ -80,7 +80,10 @@ impl_extra!(IgdbId, IgdbIdRef);

/// A game or category as defined by Twitch
#[derive(PartialEq, Eq, Debug, Clone)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(
feature = "serde",
derive(serde_derive::Serialize, serde_derive::Deserialize)
)]
#[cfg_attr(feature = "deny_unknown_fields", serde(deny_unknown_fields))]
#[non_exhaustive]
pub struct TwitchCategory {
Expand All @@ -105,7 +108,7 @@ pub struct TwitchCategory {

/// Subscription tiers
#[derive(Clone, Debug, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(Deserialize))]
#[cfg_attr(feature = "serde", derive(serde_derive::Deserialize))]
#[cfg_attr(feature = "serde", serde(field_identifier))]
pub enum SubscriptionTier {
/// Tier 1. $4.99
Expand Down Expand Up @@ -139,7 +142,10 @@ impl Serialize for SubscriptionTier {

/// Period during which the video was created
#[derive(PartialEq, Eq, Clone, Debug)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(
feature = "serde",
derive(serde_derive::Serialize, serde_derive::Deserialize)
)]
#[cfg_attr(feature = "serde", serde(rename_all = "lowercase"))]
pub enum VideoPeriod {
/// Filter by all. Effectively a no-op
Expand All @@ -154,7 +160,10 @@ pub enum VideoPeriod {

/// Type of video
#[derive(PartialEq, Eq, Clone, Debug)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(
feature = "serde",
derive(serde_derive::Serialize, serde_derive::Deserialize)
)]
#[cfg_attr(feature = "serde", serde(rename_all = "snake_case"))]
pub enum VideoType {
/// A live video
Expand Down Expand Up @@ -182,7 +191,10 @@ pub enum VideoType {

/// Type of video
#[derive(PartialEq, Eq, Clone, Debug)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(
feature = "serde",
derive(serde_derive::Serialize, serde_derive::Deserialize)
)]
#[cfg_attr(feature = "serde", serde(rename_all = "lowercase"))]
pub enum VideoPrivacy {
/// Video is public
Expand Down Expand Up @@ -303,7 +315,7 @@ impl core::fmt::Display for CommercialLengthParseError {
/// IDs for [content classification labels](https://help.twitch.tv/s/article/content-classification-labels) also known as CCLs
#[derive(Clone, Debug, PartialEq, Eq)]
#[non_exhaustive]
#[cfg_attr(feature = "serde", derive(Deserialize))]
#[cfg_attr(feature = "serde", derive(serde_derive::Deserialize))]
#[cfg_attr(feature = "serde", serde(field_identifier))]
pub enum ContentClassificationId {
/// Drugs, Intoxication, or Excessive Tobacco Use
Expand Down
Loading