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

feat: add a few new types #62

Merged
merged 13 commits into from
Oct 13, 2024
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@

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

- Added `SharedChatSessionId` and `WhisperId` (feature `chat`)
- Added `EntitlementId`, `BenefitId`, `OrganizationId`, and `EntitlementCampaignId` (feature `entitlements`)
- Added `ConduitId` and `ConduitShardId` (feature `eventsub`)
- Added `ExtensionId` (feature `extensions`)
- Added `UnbanRequestid` (feature `moderation`)
- Added `CclId`, `GuestStarSessionId`, `GuestStarSlotId`, and `StreamMarkerId` (feature `stream`)

## [v0.4.5] - 2024-04-15

[Commits](https://github.com/twitch-rs/twitch_types/compare/v0.4.4...v0.4.5)
Expand Down
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,16 @@ zerofrom = { version = "0.1.0", optional = true }
[features]
default = []

chat = []
emote = ["serde"]
entitlement = []
moderation = ["serde"]
points = ["serde"]
stream = ["serde"]
timestamp = []
user = ["serde"]
goal = ["serde"]
extension = []
eventsub = []
sub = []
color = ["serde"]
Expand Down
13 changes: 13 additions & 0 deletions src/chat.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
manual_braid! {
/// A Shared Chat Session ID
pub struct SharedChatSessionId;
pub struct SharedChatSessionIdRef;
}
impl_extra!(SharedChatSessionId, SharedChatSessionIdRef);

manual_braid! {
/// A Whisper ID
pub struct WhisperId;
pub struct WhisperIdRef;
}
impl_extra!(WhisperId, WhisperIdRef);
6 changes: 3 additions & 3 deletions src/collection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ where
}
}

fn index(&'c self, range: impl std::ops::RangeBounds<usize>) -> Option<Collection<'_, T>> {
fn index(&'c self, range: impl std::ops::RangeBounds<usize>) -> Option<Collection<'c, T>> {
let range = (range.start_bound().cloned(), range.end_bound().cloned());
let new: Collection<'_, T> = match self {
Collection::Owned(v) => Collection::Owned(Cow::Borrowed(v.get(range)?)),
Expand All @@ -162,7 +162,7 @@ where
}

/// Returns chunks of items, similar to [`slice::chunks`]
pub fn chunks(&'c self, chunk_size: usize) -> impl Iterator<Item = Collection<'_, T>> + '_ {
pub fn chunks(&'c self, chunk_size: usize) -> impl Iterator<Item = Collection<'c, T>> + 'c {
let len = self.iter().len();
let mut start = 0;
std::iter::from_fn(move || {
Expand Down Expand Up @@ -193,7 +193,7 @@ where
pub fn is_empty(&self) -> bool { self.len() == 0 }
}

impl<'a, T: std::ops::Deref + std::fmt::Debug> std::fmt::Debug for Collection<'a, T>
impl<T: std::ops::Deref + std::fmt::Debug> std::fmt::Debug for Collection<'_, T>
where
[T]: ToOwned,
<[T] as ToOwned>::Owned: std::fmt::Debug,
Expand Down
2 changes: 1 addition & 1 deletion src/color.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ impl<'a> From<Cow<'a, HexColorRef>> for NamedUserColor<'a> {
fn from(color: Cow<'a, HexColorRef>) -> Self { NamedUserColor::Hex(color) }
}

impl<'a> From<HexColor> for NamedUserColor<'a> {
impl From<HexColor> for NamedUserColor<'_> {
fn from(color: HexColor) -> Self { NamedUserColor::Hex(color.into()) }
}

Expand Down
27 changes: 27 additions & 0 deletions src/entitlement.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
manual_braid! {
/// An entitlement ID
pub struct EntitlementId;
pub struct EntitlementIdRef;
}
impl_extra!(EntitlementId, EntitlementIdRef);

manual_braid! {
/// A benefit ID
pub struct BenefitId;
pub struct BenefitIdRef;
}
impl_extra!(BenefitId, BenefitIdRef);

manual_braid! {
/// An organization ID
pub struct OrganizationId;
pub struct OrganizationIdRef;
}
impl_extra!(OrganizationId, OrganizationIdRef);

manual_braid! {
/// An entitlement campaign ID
pub struct EntitlementCampaignId;
pub struct EntitlementCampaignIdRef;
}
impl_extra!(EntitlementCampaignId, EntitlementCampaignIdRef);
14 changes: 14 additions & 0 deletions src/eventsub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,17 @@ manual_braid! {
pub struct EventSubIdRef;
}
impl_extra!(EventSubId, EventSubIdRef);

manual_braid! {
/// An ID of a Conduit
pub struct ConduitId;
pub struct ConduitIdRef;
}
impl_extra!(ConduitId, ConduitIdRef);

manual_braid! {
/// An ID of a Conduit Shard
pub struct ConduitShardId;
pub struct ConduitShardIdRef;
}
impl_extra!(ConduitShardId, ConduitShardIdRef);
6 changes: 6 additions & 0 deletions src/extension.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
manual_braid! {
/// An Extension ID
pub struct ExtensionId;
pub struct ExtensionIdRef;
}
impl_extra!(ExtensionId, ExtensionIdRef);
15 changes: 15 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,24 @@ where

mod basic;
// cc: https://github.com/rust-lang/rust/issues/83428, can't use glob imports and keep the modules private
#[cfg(feature = "chat")]
/// types for chat
pub mod chat;
#[cfg(feature = "color")]
/// types for colors
pub mod color;
#[cfg(feature = "emote")]
/// types for emotes
pub mod emote;
#[cfg(feature = "entitlement")]
/// types for entitlements
pub mod entitlement;
#[cfg(feature = "eventsub")]
/// types for eventsub related things
pub mod eventsub;
#[cfg(feature = "extension")]
/// types for extensions
pub mod extension;
#[cfg(feature = "goal")]
/// types for goals
pub mod goal;
Expand All @@ -93,12 +102,18 @@ pub mod user;

pub use basic::*;

#[cfg(feature = "chat")]
pub use crate::chat::*;
#[cfg(feature = "color")]
pub use crate::color::*;
#[cfg(feature = "emote")]
pub use crate::emote::*;
#[cfg(feature = "entitlement")]
pub use crate::entitlement::*;
#[cfg(feature = "eventsub")]
pub use crate::eventsub::*;
#[cfg(feature = "extension")]
pub use crate::extension::*;
#[cfg(feature = "goal")]
pub use crate::goal::*;
#[cfg(feature = "moderation")]
Expand Down
2 changes: 1 addition & 1 deletion src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ macro_rules! manual_braid {
impl ::std::cmp::PartialOrd for $Owned {
#[inline]
#[allow(unknown_lints)]
#[allow(clippy::incorrect_partial_ord_impl_on_ord_type)]
#[allow(clippy::non_canonical_partial_ord_impl)]
fn partial_cmp(&self, other: &Self) -> ::std::option::Option<::std::cmp::Ordering> {
::std::option::Option::Some(::std::cmp::Ord::cmp(self, other))
}
Expand Down
7 changes: 7 additions & 0 deletions src/moderation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ manual_braid! {
}
impl_extra!(BlockedTermId, BlockedTermIdRef);

manual_braid! {
/// An unban request ID
pub struct UnbanRequestId;
pub struct UnbanRequestIdRef;
}
impl_extra!(UnbanRequestId, UnbanRequestIdRef);

/// Status of a message that is or was in AutoMod queue
#[derive(PartialEq, Eq, Debug, Clone)]
#[cfg_attr(
Expand Down
21 changes: 21 additions & 0 deletions src/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,27 @@ manual_braid! {
}
impl_extra!(IgdbId, IgdbIdRef);

manual_braid! {
/// A Guest Star Session ID
pub struct GuestStarSessionId;
pub struct GuestStarSessionIdRef;
}
impl_extra!(GuestStarSessionId, GuestStarSessionIdRef);

manual_braid! {
/// A Guest Star Slot ID
pub struct GuestStarSlotId;
pub struct GuestStarSlotIdRef;
}
impl_extra!(GuestStarSlotId, GuestStarSlotIdRef);

manual_braid! {
/// A stream marker ID
pub struct StreamMarkerId;
pub struct StreamMarkerIdRef;
}
impl_extra!(StreamMarkerId, StreamMarkerIdRef);

/// A game or category as defined by Twitch
#[derive(PartialEq, Eq, Debug, Clone)]
#[cfg_attr(
Expand Down
4 changes: 2 additions & 2 deletions src/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ impl<'a> ::std::convert::From<::std::borrow::Cow<'a, TimestampRef>> for Timestam
}
}

impl<'a> ::std::convert::From<Timestamp> for ::std::borrow::Cow<'a, TimestampRef> {
impl ::std::convert::From<Timestamp> for ::std::borrow::Cow<'_, TimestampRef> {
#[inline]
fn from(owned: Timestamp) -> Self { ::std::borrow::Cow::Owned(owned) }
}
Expand All @@ -107,7 +107,7 @@ impl ::std::convert::TryFrom<::std::string::String> for Timestamp {
#[inline]
fn try_from(s: ::std::string::String) -> Result<Self, Self::Error> {
const fn ensure_try_from_string_error_converts_to_validator_error<
T: ?Sized + From<<String as ::std::convert::TryFrom<::std::string::String>>::Error>,
T: From<<String as ::std::convert::TryFrom<::std::string::String>>::Error>,
>() {
}

Expand Down
Loading