diff --git a/Cargo.toml b/Cargo.toml index 2868525..62db739 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,13 +17,13 @@ codecov = { repository = "sile/hls_m3u8" } [dependencies] thiserror = "1.0" -derive_builder = "0.8.0" -chrono = "0.4.9" -strum = { version = "0.16.0", features = ["derive"] } -derive_more = "0.15.0" -hex = "0.4.0" +derive_builder = "0.9" +chrono = "0.4" +strum = { version = "0.17", features = ["derive"] } +derive_more = "0.99" +hex = "0.4" shorthand = "0.1" [dev-dependencies] -clap = "2.33.0" -pretty_assertions = "0.6.1" +clap = "2.33" +pretty_assertions = "0.6" diff --git a/src/tags/master_playlist/i_frame_stream_inf.rs b/src/tags/master_playlist/i_frame_stream_inf.rs index 6fee28c..1a7f749 100644 --- a/src/tags/master_playlist/i_frame_stream_inf.rs +++ b/src/tags/master_playlist/i_frame_stream_inf.rs @@ -1,7 +1,8 @@ use std::fmt; -use std::ops::{Deref, DerefMut}; use std::str::FromStr; +use derive_more::{Deref, DerefMut}; + use crate::attribute::AttributePairs; use crate::types::{HdcpLevel, ProtocolVersion, StreamInf, StreamInfBuilder}; use crate::utils::{quote, tag, unquote}; @@ -18,9 +19,11 @@ use crate::{Error, RequiredVersion}; /// [`Master Playlist`]: crate::MasterPlaylist /// [`Media Playlist`]: crate::MediaPlaylist /// [4.3.5.3. EXT-X-I-FRAME-STREAM-INF]: https://tools.ietf.org/html/rfc8216#section-4.3.4.5 -#[derive(PartialOrd, Debug, Clone, PartialEq, Eq, Hash)] +#[derive(Deref, DerefMut, PartialOrd, Debug, Clone, PartialEq, Eq, Hash)] pub struct ExtXIFrameStreamInf { uri: String, + #[deref] + #[deref_mut] stream_inf: StreamInf, } @@ -180,16 +183,6 @@ impl FromStr for ExtXIFrameStreamInf { } } -impl Deref for ExtXIFrameStreamInf { - type Target = StreamInf; - - fn deref(&self) -> &Self::Target { &self.stream_inf } -} - -impl DerefMut for ExtXIFrameStreamInf { - fn deref_mut(&mut self) -> &mut Self::Target { &mut self.stream_inf } -} - #[cfg(test)] mod test { use super::*; diff --git a/src/tags/master_playlist/session_key.rs b/src/tags/master_playlist/session_key.rs index 0f23184..a46b015 100644 --- a/src/tags/master_playlist/session_key.rs +++ b/src/tags/master_playlist/session_key.rs @@ -1,7 +1,8 @@ use std::fmt; -use std::ops::{Deref, DerefMut}; use std::str::FromStr; +use derive_more::{Deref, DerefMut}; + use crate::types::{DecryptionKey, EncryptionMethod, ProtocolVersion}; use crate::utils::tag; use crate::{Error, RequiredVersion}; @@ -16,7 +17,7 @@ use crate::{Error, RequiredVersion}; /// [`Media Playlist`]: crate::MediaPlaylist /// [`Master Playlist`]: crate::MasterPlaylist /// [4.3.4.5. EXT-X-SESSION-KEY]: https://tools.ietf.org/html/rfc8216#section-4.3.4.5 -#[derive(Debug, Clone, PartialEq, Eq, Hash)] +#[derive(Deref, DerefMut, Debug, Clone, PartialEq, Eq, Hash)] pub struct ExtXSessionKey(DecryptionKey); impl ExtXSessionKey { @@ -74,16 +75,6 @@ impl FromStr for ExtXSessionKey { } } -impl Deref for ExtXSessionKey { - type Target = DecryptionKey; - - fn deref(&self) -> &Self::Target { &self.0 } -} - -impl DerefMut for ExtXSessionKey { - fn deref_mut(&mut self) -> &mut Self::Target { &mut self.0 } -} - #[cfg(test)] mod test { use super::*; diff --git a/src/tags/master_playlist/stream_inf.rs b/src/tags/master_playlist/stream_inf.rs index df7b350..fa51342 100644 --- a/src/tags/master_playlist/stream_inf.rs +++ b/src/tags/master_playlist/stream_inf.rs @@ -1,7 +1,7 @@ use std::fmt; -use std::ops::{Deref, DerefMut}; use std::str::FromStr; +use derive_more::{Deref, DerefMut}; use shorthand::ShortHand; use crate::attribute::AttributePairs; @@ -23,7 +23,7 @@ use crate::{Error, RequiredVersion}; /// Renditions SHOULD play this Rendition. /// /// [4.3.4.2. EXT-X-STREAM-INF]: https://tools.ietf.org/html/rfc8216#section-4.3.4.2 -#[derive(ShortHand, PartialOrd, Debug, Clone, PartialEq)] +#[derive(Deref, DerefMut, ShortHand, PartialOrd, Debug, Clone, PartialEq)] #[shorthand(enable(must_use, into))] pub struct ExtXStreamInf { /// The `URI` that identifies the associated media playlist. @@ -37,6 +37,8 @@ pub struct ExtXStreamInf { /// The value of the [`ClosedCaptions`] attribute. closed_captions: Option, #[shorthand(enable(skip))] + #[deref] + #[deref_mut] stream_inf: StreamInf, } @@ -249,16 +251,6 @@ impl FromStr for ExtXStreamInf { } } -impl Deref for ExtXStreamInf { - type Target = StreamInf; - - fn deref(&self) -> &Self::Target { &self.stream_inf } -} - -impl DerefMut for ExtXStreamInf { - fn deref_mut(&mut self) -> &mut Self::Target { &mut self.stream_inf } -} - #[cfg(test)] mod test { use super::*; diff --git a/src/tags/media_playlist/target_duration.rs b/src/tags/media_playlist/target_duration.rs index 0165154..16c631b 100644 --- a/src/tags/media_playlist/target_duration.rs +++ b/src/tags/media_playlist/target_duration.rs @@ -1,8 +1,9 @@ use std::fmt; -use std::ops::Deref; use std::str::FromStr; use std::time::Duration; +use derive_more::Deref; + use crate::types::ProtocolVersion; use crate::utils::tag; use crate::{Error, RequiredVersion}; @@ -15,7 +16,7 @@ use crate::{Error, RequiredVersion}; /// [`MediaSegment`]: crate::MediaSegment /// [4.3.3.1. EXT-X-TARGETDURATION]: /// https://tools.ietf.org/html/rfc8216#section-4.3.3.1 -#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default, PartialOrd, Ord)] +#[derive(Deref, Debug, Clone, Copy, PartialEq, Eq, Hash, Default, PartialOrd, Ord)] pub struct ExtXTargetDuration(Duration); impl ExtXTargetDuration { @@ -57,12 +58,6 @@ impl RequiredVersion for ExtXTargetDuration { fn required_version(&self) -> ProtocolVersion { ProtocolVersion::V1 } } -impl Deref for ExtXTargetDuration { - type Target = Duration; - - fn deref(&self) -> &Self::Target { &self.0 } -} - impl fmt::Display for ExtXTargetDuration { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{}{}", Self::PREFIX, self.0.as_secs()) diff --git a/src/tags/media_segment/byte_range.rs b/src/tags/media_segment/byte_range.rs index 3a04489..9af41ca 100644 --- a/src/tags/media_segment/byte_range.rs +++ b/src/tags/media_segment/byte_range.rs @@ -1,7 +1,8 @@ use std::fmt; -use std::ops::{Deref, DerefMut}; use std::str::FromStr; +use derive_more::{Deref, DerefMut}; + use crate::types::{ByteRange, ProtocolVersion}; use crate::utils::tag; use crate::{Error, RequiredVersion}; @@ -14,7 +15,7 @@ use crate::{Error, RequiredVersion}; /// [`Media Segment`]: crate::MediaSegment /// [4.4.2.2. EXT-X-BYTERANGE]: /// https://tools.ietf.org/html/draft-pantos-hls-rfc8216bis-04#section-4.4.2.2 -#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)] +#[derive(Deref, DerefMut, Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)] pub struct ExtXByteRange(ByteRange); impl ExtXByteRange { @@ -51,16 +52,6 @@ impl RequiredVersion for ExtXByteRange { fn required_version(&self) -> ProtocolVersion { ProtocolVersion::V4 } } -impl Deref for ExtXByteRange { - type Target = ByteRange; - - fn deref(&self) -> &Self::Target { &self.0 } -} - -impl DerefMut for ExtXByteRange { - fn deref_mut(&mut self) -> &mut Self::Target { &mut self.0 } -} - impl fmt::Display for ExtXByteRange { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{}", Self::PREFIX)?; diff --git a/src/tags/media_segment/key.rs b/src/tags/media_segment/key.rs index b875861..acf3e02 100644 --- a/src/tags/media_segment/key.rs +++ b/src/tags/media_segment/key.rs @@ -1,7 +1,8 @@ use std::fmt; -use std::ops::{Deref, DerefMut}; use std::str::FromStr; +use derive_more::{Deref, DerefMut}; + use crate::types::{DecryptionKey, EncryptionMethod, ProtocolVersion}; use crate::utils::tag; use crate::{Error, RequiredVersion}; @@ -23,7 +24,7 @@ use crate::{Error, RequiredVersion}; /// [`ExtXMap`]: crate::tags::ExtXMap /// [`Media Segment`]: crate::MediaSegment /// [4.3.2.4. EXT-X-KEY]: https://tools.ietf.org/html/rfc8216#section-4.3.2.4 -#[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)] +#[derive(Deref, DerefMut, Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)] pub struct ExtXKey(DecryptionKey); impl ExtXKey { @@ -105,16 +106,6 @@ impl fmt::Display for ExtXKey { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{}{}", Self::PREFIX, self.0) } } -impl Deref for ExtXKey { - type Target = DecryptionKey; - - fn deref(&self) -> &Self::Target { &self.0 } -} - -impl DerefMut for ExtXKey { - fn deref_mut(&mut self) -> &mut Self::Target { &mut self.0 } -} - #[cfg(test)] mod test { use super::*; diff --git a/src/tags/media_segment/program_date_time.rs b/src/tags/media_segment/program_date_time.rs index a948ee9..ff91b00 100644 --- a/src/tags/media_segment/program_date_time.rs +++ b/src/tags/media_segment/program_date_time.rs @@ -1,8 +1,8 @@ use std::fmt; -use std::ops::{Deref, DerefMut}; use std::str::FromStr; use chrono::{DateTime, FixedOffset, SecondsFormat}; +use derive_more::{Deref, DerefMut}; use crate::types::ProtocolVersion; use crate::utils::tag; @@ -16,7 +16,7 @@ use crate::{Error, RequiredVersion}; /// [`Media Segment`]: crate::MediaSegment /// [4.3.2.6. EXT-X-PROGRAM-DATE-TIME]: /// https://tools.ietf.org/html/rfc8216#section-4.3.2.6 -#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)] +#[derive(Deref, DerefMut, Debug, Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)] pub struct ExtXProgramDateTime(DateTime); impl ExtXProgramDateTime { @@ -124,20 +124,11 @@ impl FromStr for ExtXProgramDateTime { } } -impl Deref for ExtXProgramDateTime { - type Target = DateTime; - - fn deref(&self) -> &Self::Target { &self.0 } -} - -impl DerefMut for ExtXProgramDateTime { - fn deref_mut(&mut self) -> &mut Self::Target { &mut self.0 } -} - #[cfg(test)] mod test { use super::*; use chrono::{Datelike, TimeZone}; + use core::ops::DerefMut; use pretty_assertions::assert_eq; const HOURS_IN_SECS: i32 = 3600; // 1 hour = 3600 seconds diff --git a/src/types/decimal_floating_point.rs b/src/types/decimal_floating_point.rs index 53aa3c7..454fb66 100644 --- a/src/types/decimal_floating_point.rs +++ b/src/types/decimal_floating_point.rs @@ -1,7 +1,6 @@ -use core::ops::Deref; use core::str::FromStr; -use derive_more::Display; +use derive_more::{Deref, Display}; use crate::Error; @@ -11,7 +10,7 @@ use crate::Error; /// /// [4.2. Attribute Lists]: /// https://tools.ietf.org/html/draft-pantos-hls-rfc8216bis-05#section-4.2 -#[derive(Default, Debug, Clone, Copy, PartialEq, PartialOrd, Display)] +#[derive(Deref, Default, Debug, Clone, Copy, PartialEq, PartialOrd, Display)] pub(crate) struct DecimalFloatingPoint(f64); impl DecimalFloatingPoint { @@ -45,12 +44,6 @@ impl FromStr for DecimalFloatingPoint { } } -impl Deref for DecimalFloatingPoint { - type Target = f64; - - fn deref(&self) -> &Self::Target { &self.0 } -} - #[doc(hidden)] impl From for DecimalFloatingPoint { fn from(value: f64) -> Self { diff --git a/src/types/key_format_versions.rs b/src/types/key_format_versions.rs index 2b4fc95..7fada99 100644 --- a/src/types/key_format_versions.rs +++ b/src/types/key_format_versions.rs @@ -1,8 +1,9 @@ use std::convert::Infallible; use std::fmt; -use std::ops::{Deref, DerefMut}; use std::str::FromStr; +use derive_more::{Deref, DerefMut}; + use crate::types::ProtocolVersion; use crate::utils::{quote, unquote}; use crate::RequiredVersion; @@ -12,7 +13,7 @@ use crate::RequiredVersion; /// [`KeyFormat`] is defined. /// /// [`KeyFormat`]: crate::types::KeyFormat -#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug)] +#[derive(Deref, DerefMut, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug)] pub struct KeyFormatVersions(Vec); impl KeyFormatVersions { @@ -37,16 +38,6 @@ impl Default for KeyFormatVersions { fn default() -> Self { Self(vec![1]) } } -impl Deref for KeyFormatVersions { - type Target = Vec; - - fn deref(&self) -> &Self::Target { &self.0 } -} - -impl DerefMut for KeyFormatVersions { - fn deref_mut(&mut self) -> &mut Self::Target { &mut self.0 } -} - /// This tag requires [`ProtocolVersion::V5`]. impl RequiredVersion for KeyFormatVersions { fn required_version(&self) -> ProtocolVersion { ProtocolVersion::V5 } diff --git a/src/types/signed_decimal_floating_point.rs b/src/types/signed_decimal_floating_point.rs index 93cbb0c..62aa32a 100644 --- a/src/types/signed_decimal_floating_point.rs +++ b/src/types/signed_decimal_floating_point.rs @@ -1,4 +1,4 @@ -use core::ops::Deref; +use derive_more::Deref; use derive_more::{Display, FromStr}; /// Signed decimal floating-point number. @@ -6,7 +6,7 @@ use derive_more::{Display, FromStr}; /// See: [4.2. Attribute Lists] /// /// [4.2. Attribute Lists]: https://tools.ietf.org/html/rfc8216#section-4.2 -#[derive(Default, Debug, Clone, Copy, PartialEq, PartialOrd, Display, FromStr)] +#[derive(Deref, Default, Debug, Clone, Copy, PartialEq, PartialOrd, Display, FromStr)] pub(crate) struct SignedDecimalFloatingPoint(f64); impl SignedDecimalFloatingPoint { @@ -28,12 +28,6 @@ impl SignedDecimalFloatingPoint { pub const fn as_f64(self) -> f64 { self.0 } } -impl Deref for SignedDecimalFloatingPoint { - type Target = f64; - - fn deref(&self) -> &Self::Target { &self.0 } -} - #[cfg(test)] mod tests { use super::*;