1
0
Fork 0
mirror of https://github.com/sile/hls_m3u8.git synced 2024-11-25 08:31:00 +00:00

added rustfmt.toml

This commit is contained in:
Luro02 2019-10-03 17:01:15 +02:00
parent 06a30d7704
commit 5eca073a8c
41 changed files with 358 additions and 749 deletions

10
rustfmt.toml Normal file
View file

@ -0,0 +1,10 @@
error_on_unformatted = true
edition = "2018"
fn_single_line = true
force_multiline_blocks = true
format_code_in_doc_comments = true
format_macro_matchers = true
match_arm_blocks = true
reorder_impl_items = true
use_field_init_shorthand = true
wrap_comments = true

View file

@ -8,41 +8,31 @@ use crate::Error;
pub struct AttributePairs(HashMap<String, String>);
impl AttributePairs {
pub fn new() -> Self {
Self::default()
}
pub fn new() -> Self { Self::default() }
}
impl Deref for AttributePairs {
type Target = HashMap<String, String>;
fn deref(&self) -> &Self::Target {
&self.0
}
fn deref(&self) -> &Self::Target { &self.0 }
}
impl DerefMut for AttributePairs {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.0
}
fn deref_mut(&mut self) -> &mut Self::Target { &mut self.0 }
}
impl IntoIterator for AttributePairs {
type Item = (String, String);
type IntoIter = ::std::collections::hash_map::IntoIter<String, String>;
type Item = (String, String);
fn into_iter(self) -> Self::IntoIter {
self.0.into_iter()
}
fn into_iter(self) -> Self::IntoIter { self.0.into_iter() }
}
impl<'a> IntoIterator for &'a AttributePairs {
type Item = (&'a String, &'a String);
type IntoIter = ::std::collections::hash_map::Iter<'a, String, String>;
type Item = (&'a String, &'a String);
fn into_iter(self) -> Self::IntoIter {
self.0.iter()
}
fn into_iter(self) -> Self::IntoIter { self.0.iter() }
}
impl FromStr for AttributePairs {

View file

@ -93,31 +93,21 @@ pub struct Error {
}
impl Fail for Error {
fn cause(&self) -> Option<&dyn Fail> {
self.inner.cause()
}
fn cause(&self) -> Option<&dyn Fail> { self.inner.cause() }
fn backtrace(&self) -> Option<&Backtrace> {
self.inner.backtrace()
}
fn backtrace(&self) -> Option<&Backtrace> { self.inner.backtrace() }
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
self.inner.fmt(f)
}
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { self.inner.fmt(f) }
}
impl From<ErrorKind> for Error {
fn from(kind: ErrorKind) -> Error {
Error::from(Context::new(kind))
}
fn from(kind: ErrorKind) -> Error { Error::from(Context::new(kind)) }
}
impl From<Context<ErrorKind>> for Error {
fn from(inner: Context<ErrorKind>) -> Error {
Error { inner }
}
fn from(inner: Context<ErrorKind>) -> Error { Error { inner } }
}
impl Error {
@ -129,9 +119,7 @@ impl Error {
Self::from(ErrorKind::UnexpectedAttribute(value.to_string()))
}
pub(crate) fn invalid_input() -> Self {
Self::from(ErrorKind::InvalidInput)
}
pub(crate) fn invalid_input() -> Self { Self::from(ErrorKind::InvalidInput) }
pub(crate) fn parse_int_error<T: ToString>(value: T) -> Self {
Self::from(ErrorKind::ParseIntError(value.to_string()))
@ -167,9 +155,7 @@ impl Error {
Self::from(ErrorKind::UnknownProtocolVersion(value.to_string()))
}
pub(crate) fn io<T: ToString>(value: T) -> Self {
Self::from(ErrorKind::Io(value.to_string()))
}
pub(crate) fn io<T: ToString>(value: T) -> Self { Self::from(ErrorKind::Io(value.to_string())) }
pub(crate) fn required_version<T, U>(required_version: T, specified_version: U) -> Self
where
@ -196,27 +182,19 @@ impl Error {
}
impl From<::std::num::ParseIntError> for Error {
fn from(value: ::std::num::ParseIntError) -> Self {
Error::parse_int_error(value)
}
fn from(value: ::std::num::ParseIntError) -> Self { Error::parse_int_error(value) }
}
impl From<::std::num::ParseFloatError> for Error {
fn from(value: ::std::num::ParseFloatError) -> Self {
Error::parse_float_error(value)
}
fn from(value: ::std::num::ParseFloatError) -> Self { Error::parse_float_error(value) }
}
impl From<::std::io::Error> for Error {
fn from(value: ::std::io::Error) -> Self {
Error::io(value)
}
fn from(value: ::std::io::Error) -> Self { Error::io(value) }
}
impl From<::chrono::ParseError> for Error {
fn from(value: ::chrono::ParseError) -> Self {
Error::chrono(value)
}
fn from(value: ::chrono::ParseError) -> Self { Error::chrono(value) }
}
impl From<::strum::ParseError> for Error {

View file

@ -9,9 +9,7 @@ use crate::Error;
pub struct Lines(Vec<Line>);
impl Lines {
pub fn new() -> Self {
Self::default()
}
pub fn new() -> Self { Self::default() }
}
impl FromStr for Lines {
@ -65,26 +63,20 @@ impl FromStr for Lines {
}
impl IntoIterator for Lines {
type Item = Line;
type IntoIter = ::std::vec::IntoIter<Line>;
type Item = Line;
fn into_iter(self) -> Self::IntoIter {
self.0.into_iter()
}
fn into_iter(self) -> Self::IntoIter { self.0.into_iter() }
}
impl Deref for Lines {
type Target = Vec<Line>;
fn deref(&self) -> &Self::Target {
&self.0
}
fn deref(&self) -> &Self::Target { &self.0 }
}
impl DerefMut for Lines {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.0
}
fn deref_mut(&mut self) -> &mut Self::Target { &mut self.0 }
}
#[derive(Debug, PartialEq, Eq)]

View file

@ -21,8 +21,8 @@ pub struct MasterPlaylist {
#[builder(default, setter(name = "version"))]
/// Sets the protocol compatibility version of the resulting playlist.
///
/// If the resulting playlist has tags which requires a compatibility version greater than
/// `version`,
/// If the resulting playlist has tags which requires a compatibility
/// version greater than `version`,
/// `build()` method will fail with an `ErrorKind::InvalidInput` error.
///
/// The default is the maximum version among the tags in the playlist.
@ -47,14 +47,10 @@ pub struct MasterPlaylist {
impl MasterPlaylist {
/// Returns a Builder for a MasterPlaylist.
pub fn builder() -> MasterPlaylistBuilder {
MasterPlaylistBuilder::default()
}
pub fn builder() -> MasterPlaylistBuilder { MasterPlaylistBuilder::default() }
/// Returns the `EXT-X-VERSION` tag contained in the playlist.
pub const fn version_tag(&self) -> ExtXVersion {
self.version_tag
}
pub const fn version_tag(&self) -> ExtXVersion { self.version_tag }
/// Returns the `EXT-X-INDEPENDENT-SEGMENTS` tag contained in the playlist.
pub const fn independent_segments_tag(&self) -> Option<ExtXIndependentSegments> {
@ -62,19 +58,13 @@ impl MasterPlaylist {
}
/// Returns the `EXT-X-START` tag contained in the playlist.
pub const fn start_tag(&self) -> Option<ExtXStart> {
self.start_tag
}
pub const fn start_tag(&self) -> Option<ExtXStart> { self.start_tag }
/// Returns the `EXT-X-MEDIA` tags contained in the playlist.
pub fn media_tags(&self) -> &[ExtXMedia] {
&self.media_tags
}
pub fn media_tags(&self) -> &[ExtXMedia] { &self.media_tags }
/// Returns the `EXT-X-STREAM-INF` tags contained in the playlist.
pub fn stream_inf_tags(&self) -> &[ExtXStreamInf] {
&self.stream_inf_tags
}
pub fn stream_inf_tags(&self) -> &[ExtXStreamInf] { &self.stream_inf_tags }
/// Returns the `EXT-X-I-FRAME-STREAM-INF` tags contained in the playlist.
pub fn i_frame_stream_inf_tags(&self) -> &[ExtXIFrameStreamInf] {
@ -82,20 +72,14 @@ impl MasterPlaylist {
}
/// Returns the `EXT-X-SESSION-DATA` tags contained in the playlist.
pub fn session_data_tags(&self) -> &[ExtXSessionData] {
&self.session_data_tags
}
pub fn session_data_tags(&self) -> &[ExtXSessionData] { &self.session_data_tags }
/// Returns the `EXT-X-SESSION-KEY` tags contained in the playlist.
pub fn session_key_tags(&self) -> &[ExtXSessionKey] {
&self.session_key_tags
}
pub fn session_key_tags(&self) -> &[ExtXSessionKey] { &self.session_key_tags }
}
impl RequiredVersion for MasterPlaylist {
fn required_version(&self) -> ProtocolVersion {
self.version_tag.version()
}
fn required_version(&self) -> ProtocolVersion { self.version_tag.version() }
}
impl MasterPlaylistBuilder {

View file

@ -53,7 +53,8 @@ pub struct MediaPlaylist {
end_list_tag: Option<ExtXEndList>,
/// Sets all [MediaSegment]s.
segments: Vec<MediaSegment>,
/// Sets the allowable excess duration of each media segment in the associated playlist.
/// Sets the allowable excess duration of each media segment in the
/// associated playlist.
///
/// # Error
/// If there is a media segment of which duration exceeds
@ -221,38 +222,28 @@ impl MediaPlaylistBuilder {
impl MediaPlaylist {
/// Creates a [MediaPlaylistBuilder].
pub fn builder() -> MediaPlaylistBuilder {
MediaPlaylistBuilder::default()
}
pub fn builder() -> MediaPlaylistBuilder { MediaPlaylistBuilder::default() }
/// Returns the `EXT-X-VERSION` tag contained in the playlist.
pub const fn version_tag(&self) -> ExtXVersion {
self.version_tag
}
pub const fn version_tag(&self) -> ExtXVersion { self.version_tag }
/// Returns the `EXT-X-TARGETDURATION` tag contained in the playlist.
pub const fn target_duration_tag(&self) -> ExtXTargetDuration {
self.target_duration_tag
}
pub const fn target_duration_tag(&self) -> ExtXTargetDuration { self.target_duration_tag }
/// Returns the `EXT-X-MEDIA-SEQUENCE` tag contained in the playlist.
pub const fn media_sequence_tag(&self) -> Option<ExtXMediaSequence> {
self.media_sequence_tag
}
pub const fn media_sequence_tag(&self) -> Option<ExtXMediaSequence> { self.media_sequence_tag }
/// Returns the `EXT-X-DISCONTINUITY-SEQUENCE` tag contained in the playlist.
/// Returns the `EXT-X-DISCONTINUITY-SEQUENCE` tag contained in the
/// playlist.
pub const fn discontinuity_sequence_tag(&self) -> Option<ExtXDiscontinuitySequence> {
self.discontinuity_sequence_tag
}
/// Returns the `EXT-X-PLAYLIST-TYPE` tag contained in the playlist.
pub const fn playlist_type_tag(&self) -> Option<ExtXPlaylistType> {
self.playlist_type_tag
}
pub const fn playlist_type_tag(&self) -> Option<ExtXPlaylistType> { self.playlist_type_tag }
/// Returns the `EXT-X-I-FRAMES-ONLY` tag contained in the playlist.
pub const fn i_frames_only_tag(&self) -> Option<ExtXIFramesOnly> {
self.i_frames_only_tag
}
pub const fn i_frames_only_tag(&self) -> Option<ExtXIFramesOnly> { self.i_frames_only_tag }
/// Returns the `EXT-X-INDEPENDENT-SEGMENTS` tag contained in the playlist.
pub const fn independent_segments_tag(&self) -> Option<ExtXIndependentSegments> {
@ -260,19 +251,13 @@ impl MediaPlaylist {
}
/// Returns the `EXT-X-START` tag contained in the playlist.
pub const fn start_tag(&self) -> Option<ExtXStart> {
self.start_tag
}
pub const fn start_tag(&self) -> Option<ExtXStart> { self.start_tag }
/// Returns the `EXT-X-ENDLIST` tag contained in the playlist.
pub const fn end_list_tag(&self) -> Option<ExtXEndList> {
self.end_list_tag
}
pub const fn end_list_tag(&self) -> Option<ExtXEndList> { self.end_list_tag }
/// Returns the media segments contained in the playlist.
pub fn segments(&self) -> &[MediaSegment] {
&self.segments
}
pub fn segments(&self) -> &[MediaSegment] { &self.segments }
}
impl fmt::Display for MediaPlaylist {

View file

@ -76,48 +76,34 @@ impl fmt::Display for MediaSegment {
impl MediaSegment {
/// Creates a [MediaSegmentBuilder].
pub fn builder() -> MediaSegmentBuilder {
MediaSegmentBuilder::default()
}
pub fn builder() -> MediaSegmentBuilder { MediaSegmentBuilder::default() }
/// Returns the URI of the media segment.
pub const fn uri(&self) -> &String {
&self.uri
}
pub const fn uri(&self) -> &String { &self.uri }
/// Returns the `EXT-X-INF` tag associated with the media segment.
pub const fn inf_tag(&self) -> &ExtInf {
&self.inf_tag
}
pub const fn inf_tag(&self) -> &ExtInf { &self.inf_tag }
/// Returns the `EXT-X-BYTERANGE` tag associated with the media segment.
pub const fn byte_range_tag(&self) -> Option<ExtXByteRange> {
self.byte_range_tag
}
pub const fn byte_range_tag(&self) -> Option<ExtXByteRange> { self.byte_range_tag }
/// Returns the `EXT-X-DATERANGE` tag associated with the media segment.
pub fn date_range_tag(&self) -> Option<&ExtXDateRange> {
self.date_range_tag.as_ref()
}
pub fn date_range_tag(&self) -> Option<&ExtXDateRange> { self.date_range_tag.as_ref() }
/// Returns the `EXT-X-DISCONTINUITY` tag associated with the media segment.
pub const fn discontinuity_tag(&self) -> Option<ExtXDiscontinuity> {
self.discontinuity_tag
}
pub const fn discontinuity_tag(&self) -> Option<ExtXDiscontinuity> { self.discontinuity_tag }
/// Returns the `EXT-X-PROGRAM-DATE-TIME` tag associated with the media segment.
/// Returns the `EXT-X-PROGRAM-DATE-TIME` tag associated with the media
/// segment.
pub fn program_date_time_tag(&self) -> Option<&ExtXProgramDateTime> {
self.program_date_time_tag.as_ref()
}
/// Returns the `EXT-X-MAP` tag associated with the media segment.
pub fn map_tag(&self) -> Option<&ExtXMap> {
self.map_tag.as_ref()
}
pub fn map_tag(&self) -> Option<&ExtXMap> { self.map_tag.as_ref() }
/// Returns the `EXT-X-KEY` tags associated with the media segment.
pub fn key_tags(&self) -> &[ExtXKey] {
&self.key_tags
}
pub fn key_tags(&self) -> &[ExtXKey] { &self.key_tags }
}
impl RequiredVersion for MediaSegment {

View file

@ -43,15 +43,11 @@ impl ExtM3u {
/// This tag requires [`ProtocolVersion::V1`].
impl RequiredVersion for ExtM3u {
fn required_version(&self) -> ProtocolVersion {
ProtocolVersion::V1
}
fn required_version(&self) -> ProtocolVersion { ProtocolVersion::V1 }
}
impl fmt::Display for ExtM3u {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", Self::PREFIX)
}
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{}", Self::PREFIX) }
}
impl FromStr for ExtM3u {

View file

@ -58,9 +58,7 @@ impl ExtXVersion {
///
/// let version = ExtXVersion::new(ProtocolVersion::V2);
/// ```
pub const fn new(version: ProtocolVersion) -> Self {
Self(version)
}
pub const fn new(version: ProtocolVersion) -> Self { Self(version) }
/// Returns the [`ProtocolVersion`] of the playlist, containing this tag.
///
@ -74,34 +72,24 @@ impl ExtXVersion {
/// ProtocolVersion::V6
/// );
/// ```
pub const fn version(self) -> ProtocolVersion {
self.0
}
pub const fn version(self) -> ProtocolVersion { self.0 }
}
/// This tag requires [`ProtocolVersion::V1`].
impl RequiredVersion for ExtXVersion {
fn required_version(&self) -> ProtocolVersion {
ProtocolVersion::V1
}
fn required_version(&self) -> ProtocolVersion { ProtocolVersion::V1 }
}
impl fmt::Display for ExtXVersion {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}{}", Self::PREFIX, self.0)
}
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{}{}", Self::PREFIX, self.0) }
}
impl Default for ExtXVersion {
fn default() -> Self {
Self(ProtocolVersion::V1)
}
fn default() -> Self { Self(ProtocolVersion::V1) }
}
impl From<ProtocolVersion> for ExtXVersion {
fn from(value: ProtocolVersion) -> Self {
Self(value)
}
fn from(value: ProtocolVersion) -> Self { Self(value) }
}
impl FromStr for ExtXVersion {

View file

@ -51,9 +51,7 @@ impl ExtXIFrameStreamInf {
/// ```
///
/// [`media playlist`]: crate::MediaPlaylist
pub const fn uri(&self) -> &String {
&self.uri
}
pub const fn uri(&self) -> &String { &self.uri }
/// Sets the `URI`, that identifies the associated [`media playlist`].
///
@ -76,9 +74,7 @@ impl ExtXIFrameStreamInf {
/// This tag requires [`ProtocolVersion::V1`].
impl RequiredVersion for ExtXIFrameStreamInf {
fn required_version(&self) -> ProtocolVersion {
ProtocolVersion::V1
}
fn required_version(&self) -> ProtocolVersion { ProtocolVersion::V1 }
}
impl fmt::Display for ExtXIFrameStreamInf {
@ -115,15 +111,11 @@ impl FromStr for ExtXIFrameStreamInf {
impl Deref for ExtXIFrameStreamInf {
type Target = StreamInf;
fn deref(&self) -> &Self::Target {
&self.stream_inf
}
fn deref(&self) -> &Self::Target { &self.stream_inf }
}
impl DerefMut for ExtXIFrameStreamInf {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.stream_inf
}
fn deref_mut(&mut self) -> &mut Self::Target { &mut self.stream_inf }
}
#[cfg(test)]

View file

@ -35,13 +35,15 @@ pub struct ExtXMedia {
/// Sets the `URI` that identifies the [`Media Playlist`].
///
/// # Note
/// - This attribute is **required**, if the [`MediaType`] is [`MediaType::Subtitles`].
/// - This attribute is **required**, if the [`MediaType`] is
/// [`MediaType::Subtitles`].
/// - This attribute is **not allowed**, if the [`MediaType`] is
/// [`MediaType::ClosedCaptions`].
///
/// [`Media Playlist`]: crate::MediaPlaylist
uri: Option<String>,
/// Sets the identifier, that specifies the group to which the rendition belongs.
/// Sets the identifier, that specifies the group to which the rendition
/// belongs.
///
/// # Note
/// This attribute is **required**.
@ -68,7 +70,8 @@ pub struct ExtXMedia {
/// # Note
/// This attribute is **required**.
///
/// If the [`language`] attribute is present, this attribute should be in that language.
/// If the [`language`] attribute is present, this attribute should be in
/// that language.
///
/// [`language`]: #method.language
name: String,
@ -76,19 +79,22 @@ pub struct ExtXMedia {
/// Sets the value of the `default` flag.
///
/// # Note
/// This attribute is **optional**, its absence indicates an implicit value of `false`.
/// This attribute is **optional**, its absence indicates an implicit value
/// of `false`.
is_default: bool,
#[builder(default)]
/// Sets the value of the `autoselect` flag.
///
/// # Note
/// This attribute is **optional**, its absence indicates an implicit value of `false`.
/// This attribute is **optional**, its absence indicates an implicit value
/// of `false`.
is_autoselect: bool,
#[builder(default)]
/// Sets the value of the `forced` flag.
is_forced: bool,
#[builder(setter(strip_option, into), default)]
/// Sets the identifier that specifies a rendition within the segments in the media playlist.
/// Sets the identifier that specifies a rendition within the segments in
/// the media playlist.
instream_id: Option<InStreamId>,
#[builder(setter(strip_option, into), default)]
/// Sets the string that represents uniform type identifiers (UTI).
@ -156,9 +162,7 @@ impl ExtXMedia {
}
/// Returns a builder for [`ExtXMedia`].
pub fn builder() -> ExtXMediaBuilder {
ExtXMediaBuilder::default()
}
pub fn builder() -> ExtXMediaBuilder { ExtXMediaBuilder::default() }
/// Returns the type of the media, associated with this tag.
///
@ -172,9 +176,7 @@ impl ExtXMedia {
/// MediaType::Audio
/// );
/// ```
pub const fn media_type(&self) -> MediaType {
self.media_type
}
pub const fn media_type(&self) -> MediaType { self.media_type }
/// Sets the type of the media, associated with this tag.
///
@ -187,17 +189,15 @@ impl ExtXMedia {
///
/// media.set_media_type(MediaType::Video);
///
/// assert_eq!(
/// media.media_type(),
/// MediaType::Video
/// );
/// assert_eq!(media.media_type(), MediaType::Video);
/// ```
pub fn set_media_type(&mut self, value: MediaType) -> &mut Self {
self.media_type = value;
self
}
/// Returns the identifier that specifies the group to which the rendition belongs.
/// Returns the identifier that specifies the group to which the rendition
/// belongs.
///
/// # Example
/// ```
@ -209,11 +209,10 @@ impl ExtXMedia {
/// &"audio".to_string()
/// );
/// ```
pub const fn group_id(&self) -> &String {
&self.group_id
}
pub const fn group_id(&self) -> &String { &self.group_id }
/// Sets the identifier that specifies the group, to which the rendition belongs.
/// Sets the identifier that specifies the group, to which the rendition
/// belongs.
///
/// # Example
/// ```
@ -224,10 +223,7 @@ impl ExtXMedia {
///
/// media.set_group_id("video");
///
/// assert_eq!(
/// media.group_id(),
/// &"video".to_string()
/// );
/// assert_eq!(media.group_id(), &"video".to_string());
/// ```
pub fn set_group_id<T: Into<String>>(&mut self, value: T) -> &mut Self {
self.group_id = value.into();
@ -246,14 +242,13 @@ impl ExtXMedia {
/// &"name".to_string()
/// );
/// ```
pub const fn name(&self) -> &String {
&self.name
}
pub const fn name(&self) -> &String { &self.name }
/// Sets a human-readable description of the rendition.
///
/// # Note
/// If the [`language`] attribute is present, this attribute should be in that language.
/// If the [`language`] attribute is present, this attribute should be in
/// that language.
///
/// # Example
/// ```
@ -264,10 +259,7 @@ impl ExtXMedia {
///
/// media.set_name("new_name");
///
/// assert_eq!(
/// media.name(),
/// &"new_name".to_string()
/// );
/// assert_eq!(media.name(), &"new_name".to_string());
/// ```
///
/// [`language`]: #method.language
@ -288,23 +280,18 @@ impl ExtXMedia {
///
/// media.set_uri(Some("https://www.example.com/"));
///
/// assert_eq!(
/// media.uri(),
/// &Some("https://www.example.com/".into())
/// );
/// assert_eq!(media.uri(), &Some("https://www.example.com/".into()));
/// ```
///
/// [`Media Playlist`]: crate::MediaPlaylist
pub const fn uri(&self) -> &Option<String> {
&self.uri
}
pub const fn uri(&self) -> &Option<String> { &self.uri }
/// Sets the `URI`, that identifies the [`Media Playlist`].
///
/// # Note
/// This attribute is **required**, if the [`MediaType`] is [`MediaType::Subtitles`].
/// This attribute is **not allowed**, if the [`MediaType`] is
/// [`MediaType::ClosedCaptions`].
/// This attribute is **required**, if the [`MediaType`] is
/// [`MediaType::Subtitles`]. This attribute is **not allowed**, if the
/// [`MediaType`] is [`MediaType::ClosedCaptions`].
///
/// # Example
/// ```
@ -316,10 +303,7 @@ impl ExtXMedia {
///
/// media.set_uri(Some("https://www.example.com/"));
///
/// assert_eq!(
/// media.uri(),
/// &Some("https://www.example.com/".into())
/// );
/// assert_eq!(media.uri(), &Some("https://www.example.com/".into()));
/// ```
///
/// [`Media Playlist`]: crate::MediaPlaylist
@ -340,14 +324,9 @@ impl ExtXMedia {
///
/// media.set_language(Some("english"));
///
/// assert_eq!(
/// media.language(),
/// &Some("english".into())
/// );
/// assert_eq!(media.language(), &Some("english".into()));
/// ```
pub const fn language(&self) -> &Option<String> {
&self.language
}
pub const fn language(&self) -> &Option<String> { &self.language }
/// Sets the name of the primary language used in the rendition.
/// The value has to conform to [`RFC5646`].
@ -362,10 +341,7 @@ impl ExtXMedia {
///
/// media.set_language(Some("english"));
///
/// assert_eq!(
/// media.language(),
/// &Some("english".into())
/// );
/// assert_eq!(media.language(), &Some("english".into()));
/// ```
///
/// [`RFC5646`]: https://tools.ietf.org/html/rfc5646
@ -386,14 +362,9 @@ impl ExtXMedia {
///
/// media.set_assoc_language(Some("spanish"));
///
/// assert_eq!(
/// media.assoc_language(),
/// &Some("spanish".into())
/// );
/// assert_eq!(media.assoc_language(), &Some("spanish".into()));
/// ```
pub const fn assoc_language(&self) -> &Option<String> {
&self.assoc_language
}
pub const fn assoc_language(&self) -> &Option<String> { &self.assoc_language }
/// Sets the name of a language associated with the rendition.
/// An associated language is often used in a different role, than the
@ -410,10 +381,7 @@ impl ExtXMedia {
///
/// media.set_assoc_language(Some("spanish"));
///
/// assert_eq!(
/// media.assoc_language(),
/// &Some("spanish".into())
/// );
/// assert_eq!(media.assoc_language(), &Some("spanish".into()));
/// ```
///
/// [`language`]: #method.language
@ -434,14 +402,9 @@ impl ExtXMedia {
///
/// media.set_default(true);
///
/// assert_eq!(
/// media.is_default(),
/// true
/// );
/// assert_eq!(media.is_default(), true);
/// ```
pub const fn is_default(&self) -> bool {
self.is_default
}
pub const fn is_default(&self) -> bool { self.is_default }
/// Sets the `default` flag.
/// A value of `true` indicates, that the client should play
@ -480,9 +443,7 @@ impl ExtXMedia {
///
/// assert_eq!(media.is_autoselect(), true);
/// ```
pub const fn is_autoselect(&self) -> bool {
self.is_autoselect
}
pub const fn is_autoselect(&self) -> bool { self.is_autoselect }
/// Sets the `autoselect` flag.
///
@ -503,7 +464,8 @@ impl ExtXMedia {
self
}
/// Returns whether the rendition contains content that is considered essential to play.
/// Returns whether the rendition contains content that is considered
/// essential to play.
///
/// # Example
/// ```
@ -517,9 +479,7 @@ impl ExtXMedia {
///
/// assert_eq!(media.is_forced(), true);
/// ```
pub const fn is_forced(&self) -> bool {
self.is_forced
}
pub const fn is_forced(&self) -> bool { self.is_forced }
/// Sets the `forced` flag.
///
@ -540,8 +500,8 @@ impl ExtXMedia {
self
}
/// Returns the identifier that specifies a rendition within the segments in the
/// [`Media Playlist`].
/// Returns the identifier that specifies a rendition within the segments in
/// the [`Media Playlist`].
///
/// # Example
/// ```
@ -557,9 +517,7 @@ impl ExtXMedia {
/// ```
///
/// [`Media Playlist`]: crate::MediaPlaylist
pub const fn instream_id(&self) -> Option<InStreamId> {
self.instream_id
}
pub const fn instream_id(&self) -> Option<InStreamId> { self.instream_id }
/// Sets the [`InStreamId`], that specifies a rendition within the
/// segments in the [`Media Playlist`].
@ -597,9 +555,7 @@ impl ExtXMedia {
///
/// assert_eq!(media.characteristics(), &Some("characteristic".into()));
/// ```
pub const fn characteristics(&self) -> &Option<String> {
&self.characteristics
}
pub const fn characteristics(&self) -> &Option<String> { &self.characteristics }
/// Sets the characteristics attribute, containing one or more Uniform Type
/// Identifiers separated by comma.
@ -650,9 +606,7 @@ impl ExtXMedia {
///
/// assert_eq!(media.channels(), &Some(Channels::new(6)));
/// ```
pub const fn channels(&self) -> &Option<Channels> {
&self.channels
}
pub const fn channels(&self) -> &Option<Channels> { &self.channels }
/// Sets the channels.
///
@ -772,7 +726,8 @@ impl FromStr for ExtXMedia {
}
_ => {
// [6.3.1. General Client Responsibilities]
// > ignore any attribute/value pair with an unrecognized AttributeName.
// > ignore any attribute/value pair with an unrecognized
// AttributeName.
}
}
}

View file

@ -11,9 +11,11 @@ use crate::Error;
/// The data of an [ExtXSessionData] tag.
#[derive(Hash, Eq, Ord, Debug, PartialEq, Clone, PartialOrd)]
pub enum SessionData {
/// A String, that contains the data identified by [`data_id`](ExtXSessionData::data_id).
/// If a [`language`](ExtXSessionData::language) is specified, the value should
/// contain a human-readable string written in the specified language.
/// A String, that contains the data identified by
/// [`data_id`](ExtXSessionData::data_id).
/// If a [`language`](ExtXSessionData::language) is specified, the value
/// should contain a human-readable string written in the specified
/// language.
Value(String),
/// An [`uri`], which points to a [`json`].
///
@ -61,7 +63,7 @@ impl ExtXSessionData {
///
/// ExtXSessionData::new(
/// "com.example.movie.title",
/// SessionData::Uri("https://www.example.com/".to_string())
/// SessionData::Uri("https://www.example.com/".to_string()),
/// );
/// ```
pub fn new<T: ToString>(data_id: T, data: SessionData) -> Self {
@ -94,9 +96,7 @@ impl ExtXSessionData {
/// )
/// );
/// ```
pub fn builder() -> ExtXSessionDataBuilder {
ExtXSessionDataBuilder::default()
}
pub fn builder() -> ExtXSessionDataBuilder { ExtXSessionDataBuilder::default() }
/// Makes a new [`ExtXSessionData`] tag, with the given language.
///
@ -107,7 +107,7 @@ impl ExtXSessionData {
/// let session_data = ExtXSessionData::with_language(
/// "com.example.movie.title",
/// SessionData::Value("some data".to_string()),
/// "english"
/// "english",
/// );
/// ```
pub fn with_language<T: ToString>(data_id: T, data: SessionData, language: T) -> Self {
@ -134,9 +134,7 @@ impl ExtXSessionData {
/// &"com.example.movie.title".to_string()
/// )
/// ```
pub const fn data_id(&self) -> &String {
&self.data_id
}
pub const fn data_id(&self) -> &String { &self.data_id }
/// Returns the `data`.
///
@ -154,11 +152,10 @@ impl ExtXSessionData {
/// &SessionData::Value("some data".to_string())
/// )
/// ```
pub const fn data(&self) -> &SessionData {
&self.data
}
pub const fn data(&self) -> &SessionData { &self.data }
/// Returns the `language` tag, that identifies the language of [`SessionData`].
/// Returns the `language` tag, that identifies the language of
/// [`SessionData`].
///
/// # Example
/// ```
@ -175,12 +172,10 @@ impl ExtXSessionData {
/// &Some("english".to_string())
/// )
/// ```
pub const fn language(&self) -> &Option<String> {
&self.language
}
pub const fn language(&self) -> &Option<String> { &self.language }
/// Sets the `language` attribute, that identifies the language of [`SessionData`].
/// See [rfc5646](https://tools.ietf.org/html/rfc5646).
/// Sets the `language` attribute, that identifies the language of
/// [`SessionData`]. See [rfc5646](https://tools.ietf.org/html/rfc5646).
///
/// # Example
/// ```
@ -201,8 +196,8 @@ impl ExtXSessionData {
self
}
/// Sets the `data_id` attribute, that should conform to a [reverse DNS] naming convention,
/// such as `com.example.movie.title`.
/// Sets the `data_id` attribute, that should conform to a [reverse DNS]
/// naming convention, such as `com.example.movie.title`.
///
/// # Note:
/// There is no central registration authority, so a value
@ -251,9 +246,7 @@ impl ExtXSessionData {
}
impl RequiredVersion for ExtXSessionData {
fn required_version(&self) -> ProtocolVersion {
ProtocolVersion::V1
}
fn required_version(&self) -> ProtocolVersion { ProtocolVersion::V1 }
}
impl fmt::Display for ExtXSessionData {
@ -293,7 +286,8 @@ impl FromStr for ExtXSessionData {
"LANGUAGE" => language = Some(unquote(value)),
_ => {
// [6.3.1. General Client Responsibilities]
// > ignore any attribute/value pair with an unrecognized AttributeName.
// > ignore any attribute/value pair with an unrecognized
// AttributeName.
}
}
}

View file

@ -39,10 +39,7 @@ impl ExtXSessionKey {
/// # use hls_m3u8::tags::ExtXSessionKey;
/// use hls_m3u8::types::EncryptionMethod;
///
/// let session_key = ExtXSessionKey::new(
/// EncryptionMethod::Aes128,
/// "https://www.example.com/"
/// );
/// let session_key = ExtXSessionKey::new(EncryptionMethod::Aes128, "https://www.example.com/");
/// ```
pub fn new<T: ToString>(method: EncryptionMethod, uri: T) -> Self {
if method == EncryptionMethod::None {
@ -54,9 +51,7 @@ impl ExtXSessionKey {
}
impl RequiredVersion for ExtXSessionKey {
fn required_version(&self) -> ProtocolVersion {
self.0.required_version()
}
fn required_version(&self) -> ProtocolVersion { self.0.required_version() }
}
impl fmt::Display for ExtXSessionKey {
@ -80,15 +75,11 @@ impl FromStr for ExtXSessionKey {
impl Deref for ExtXSessionKey {
type Target = DecryptionKey;
fn deref(&self) -> &Self::Target {
&self.0
}
fn deref(&self) -> &Self::Target { &self.0 }
}
impl DerefMut for ExtXSessionKey {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.0
}
fn deref_mut(&mut self) -> &mut Self::Target { &mut self.0 }
}
#[cfg(test)]
@ -171,9 +162,7 @@ mod test {
#[should_panic]
// ExtXSessionKey::new should panic, if the provided
// EncryptionMethod is None!
fn test_new_panic() {
ExtXSessionKey::new(EncryptionMethod::None, "");
}
fn test_new_panic() { ExtXSessionKey::new(EncryptionMethod::None, ""); }
#[test]
#[should_panic]

View file

@ -52,9 +52,7 @@ impl ExtXStreamInf {
///
/// assert_eq!(stream.uri(), &"https://www.example.com/".to_string());
/// ```
pub const fn uri(&self) -> &String {
&self.uri
}
pub const fn uri(&self) -> &String { &self.uri }
/// Sets the `URI` that identifies the associated media playlist.
///
@ -98,9 +96,7 @@ impl ExtXStreamInf {
/// stream.set_frame_rate(Some(59.9));
/// assert_eq!(stream.frame_rate(), Some(59.9));
/// ```
pub fn frame_rate(&self) -> Option<f64> {
self.frame_rate.map(|v| v.as_f64())
}
pub fn frame_rate(&self) -> Option<f64> { self.frame_rate.map(|v| v.as_f64()) }
/// Returns the group identifier for the audio in the variant stream.
///
@ -113,9 +109,7 @@ impl ExtXStreamInf {
/// stream.set_audio(Some("audio"));
/// assert_eq!(stream.audio(), &Some("audio".to_string()));
/// ```
pub const fn audio(&self) -> &Option<String> {
&self.audio
}
pub const fn audio(&self) -> &Option<String> { &self.audio }
/// Sets the group identifier for the audio in the variant stream.
///
@ -144,9 +138,7 @@ impl ExtXStreamInf {
/// stream.set_subtitles(Some("subs"));
/// assert_eq!(stream.subtitles(), &Some("subs".to_string()));
/// ```
pub const fn subtitles(&self) -> &Option<String> {
&self.subtitles
}
pub const fn subtitles(&self) -> &Option<String> { &self.subtitles }
/// Sets the group identifier for the subtitles in the variant stream.
///
@ -177,9 +169,7 @@ impl ExtXStreamInf {
/// stream.set_closed_captions(Some(ClosedCaptions::None));
/// assert_eq!(stream.closed_captions(), &Some(ClosedCaptions::None));
/// ```
pub const fn closed_captions(&self) -> &Option<ClosedCaptions> {
&self.closed_captions
}
pub const fn closed_captions(&self) -> &Option<ClosedCaptions> { &self.closed_captions }
/// Returns the value of [`ClosedCaptions`] attribute.
///
@ -201,9 +191,7 @@ impl ExtXStreamInf {
}
impl RequiredVersion for ExtXStreamInf {
fn required_version(&self) -> ProtocolVersion {
ProtocolVersion::V1
}
fn required_version(&self) -> ProtocolVersion { ProtocolVersion::V1 }
}
impl fmt::Display for ExtXStreamInf {
@ -267,15 +255,11 @@ impl FromStr for ExtXStreamInf {
impl Deref for ExtXStreamInf {
type Target = StreamInf;
fn deref(&self) -> &Self::Target {
&self.stream_inf
}
fn deref(&self) -> &Self::Target { &self.stream_inf }
}
impl DerefMut for ExtXStreamInf {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.stream_inf
}
fn deref_mut(&mut self) -> &mut Self::Target { &mut self.stream_inf }
}
#[cfg(test)]

View file

@ -33,9 +33,7 @@ impl ExtXDiscontinuitySequence {
/// # use hls_m3u8::tags::ExtXDiscontinuitySequence;
/// let discontinuity_sequence = ExtXDiscontinuitySequence::new(5);
/// ```
pub const fn new(seq_num: u64) -> Self {
Self(seq_num)
}
pub const fn new(seq_num: u64) -> Self { Self(seq_num) }
/// Returns the discontinuity sequence number of
/// the first media segment that appears in the associated playlist.
@ -47,9 +45,7 @@ impl ExtXDiscontinuitySequence {
///
/// assert_eq!(discontinuity_sequence.seq_num(), 5);
/// ```
pub const fn seq_num(self) -> u64 {
self.0
}
pub const fn seq_num(self) -> u64 { self.0 }
/// Sets the sequence number.
///
@ -68,15 +64,11 @@ impl ExtXDiscontinuitySequence {
}
impl RequiredVersion for ExtXDiscontinuitySequence {
fn required_version(&self) -> ProtocolVersion {
ProtocolVersion::V1
}
fn required_version(&self) -> ProtocolVersion { ProtocolVersion::V1 }
}
impl fmt::Display for ExtXDiscontinuitySequence {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}{}", Self::PREFIX, self.0)
}
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{}{}", Self::PREFIX, self.0) }
}
impl FromStr for ExtXDiscontinuitySequence {

View file

@ -26,15 +26,11 @@ impl ExtXEndList {
}
impl RequiredVersion for ExtXEndList {
fn required_version(&self) -> ProtocolVersion {
ProtocolVersion::V1
}
fn required_version(&self) -> ProtocolVersion { ProtocolVersion::V1 }
}
impl fmt::Display for ExtXEndList {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
Self::PREFIX.fmt(f)
}
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { Self::PREFIX.fmt(f) }
}
impl FromStr for ExtXEndList {

View file

@ -28,15 +28,11 @@ impl ExtXIFramesOnly {
}
impl RequiredVersion for ExtXIFramesOnly {
fn required_version(&self) -> ProtocolVersion {
ProtocolVersion::V4
}
fn required_version(&self) -> ProtocolVersion { ProtocolVersion::V4 }
}
impl fmt::Display for ExtXIFramesOnly {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
Self::PREFIX.fmt(f)
}
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { Self::PREFIX.fmt(f) }
}
impl FromStr for ExtXIFramesOnly {
@ -61,9 +57,7 @@ mod test {
}
#[test]
fn test_parser() {
assert_eq!(ExtXIFramesOnly, "#EXT-X-I-FRAMES-ONLY".parse().unwrap(),)
}
fn test_parser() { assert_eq!(ExtXIFramesOnly, "#EXT-X-I-FRAMES-ONLY".parse().unwrap(),) }
#[test]
fn test_required_version() {

View file

@ -31,9 +31,7 @@ impl ExtXMediaSequence {
/// # use hls_m3u8::tags::ExtXMediaSequence;
/// let media_sequence = ExtXMediaSequence::new(5);
/// ```
pub const fn new(seq_num: u64) -> Self {
Self(seq_num)
}
pub const fn new(seq_num: u64) -> Self { Self(seq_num) }
/// Returns the sequence number of the first media segment,
/// that appears in the associated playlist.
@ -45,9 +43,7 @@ impl ExtXMediaSequence {
///
/// assert_eq!(media_sequence.seq_num(), 5);
/// ```
pub const fn seq_num(self) -> u64 {
self.0
}
pub const fn seq_num(self) -> u64 { self.0 }
/// Sets the sequence number.
///
@ -66,15 +62,11 @@ impl ExtXMediaSequence {
}
impl RequiredVersion for ExtXMediaSequence {
fn required_version(&self) -> ProtocolVersion {
ProtocolVersion::V1
}
fn required_version(&self) -> ProtocolVersion { ProtocolVersion::V1 }
}
impl fmt::Display for ExtXMediaSequence {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}{}", Self::PREFIX, self.0)
}
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{}{}", Self::PREFIX, self.0) }
}
impl FromStr for ExtXMediaSequence {

View file

@ -33,9 +33,7 @@ impl ExtXPlaylistType {
}
impl RequiredVersion for ExtXPlaylistType {
fn required_version(&self) -> ProtocolVersion {
ProtocolVersion::V1
}
fn required_version(&self) -> ProtocolVersion { ProtocolVersion::V1 }
}
impl fmt::Display for ExtXPlaylistType {

View file

@ -47,16 +47,12 @@ impl ExtXTargetDuration {
///
/// assert_eq!(target_duration.duration(), Duration::from_secs(2));
/// ```
pub const fn duration(&self) -> Duration {
self.0
}
pub const fn duration(&self) -> Duration { self.0 }
}
/// This tag requires [`ProtocolVersion::V1`].
impl RequiredVersion for ExtXTargetDuration {
fn required_version(&self) -> ProtocolVersion {
ProtocolVersion::V1
}
fn required_version(&self) -> ProtocolVersion { ProtocolVersion::V1 }
}
impl fmt::Display for ExtXTargetDuration {

View file

@ -50,29 +50,21 @@ impl ExtXByteRange {
/// let byte_range = ExtXByteRange::new(20, Some(5));
/// let range: ByteRange = byte_range.to_range();
/// ```
pub const fn to_range(&self) -> ByteRange {
self.0
}
pub const fn to_range(&self) -> ByteRange { self.0 }
}
impl RequiredVersion for ExtXByteRange {
fn required_version(&self) -> ProtocolVersion {
ProtocolVersion::V4
}
fn required_version(&self) -> ProtocolVersion { ProtocolVersion::V4 }
}
impl Deref for ExtXByteRange {
type Target = ByteRange;
fn deref(&self) -> &Self::Target {
&self.0
}
fn deref(&self) -> &Self::Target { &self.0 }
}
impl DerefMut for ExtXByteRange {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.0
}
fn deref_mut(&mut self) -> &mut Self::Target { &mut self.0 }
}
impl fmt::Display for ExtXByteRange {

View file

@ -21,14 +21,15 @@ pub struct ExtXDateRange {
/// A string that uniquely identifies a [`ExtXDateRange`] in the Playlist.
/// This attribute is required.
id: String,
/// A client-defined string that specifies some set of attributes and their associated value
/// semantics. All Date Ranges with the same CLASS attribute value MUST adhere to these
/// semantics. This attribute is OPTIONAL.
/// A client-defined string that specifies some set of attributes and their
/// associated value semantics. All Date Ranges with the same CLASS
/// attribute value MUST adhere to these semantics. This attribute is
/// OPTIONAL.
class: Option<String>,
/// The date at which the Date Range begins. This attribute is REQUIRED.
start_date: DateTime<FixedOffset>,
/// The date at which the Date Range ends. It MUST be equal to or later than the value of the
/// START-DATE attribute. This attribute is OPTIONAL.
/// The date at which the Date Range ends. It MUST be equal to or later than
/// the value of the START-DATE attribute. This attribute is OPTIONAL.
end_date: Option<DateTime<FixedOffset>>,
/// The duration of the Date Range. It MUST NOT be negative. A single
/// instant in time (e.g., crossing a finish line) SHOULD be
@ -45,11 +46,11 @@ pub struct ExtXDateRange {
scte35_out: Option<String>,
///
scte35_in: Option<String>,
/// This attribute indicates that the end of the range containing it is equal to the
/// START-DATE of its Following Range. The Following Range is the
/// Date Range of the same CLASS, that has the earliest START-DATE
/// after the START-DATE of the range in question. This attribute is
/// OPTIONAL.
/// This attribute indicates that the end of the range containing it is
/// equal to the START-DATE of its Following Range. The Following Range
/// is the Date Range of the same CLASS, that has the earliest
/// START-DATE after the START-DATE of the range in question. This
/// attribute is OPTIONAL.
end_on_next: bool,
/// The "X-" prefix defines a namespace reserved for client-defined
/// attributes. The client-attribute MUST be a legal AttributeName.
@ -69,14 +70,17 @@ impl ExtXDateRange {
/// # Example
/// ```
/// # use hls_m3u8::tags::ExtXDateRange;
/// use chrono::{DateTime, FixedOffset};
/// use chrono::offset::TimeZone;
/// use chrono::{DateTime, FixedOffset};
///
/// const HOURS_IN_SECS: i32 = 3600; // 1 hour = 3600 seconds
///
/// let date_range = ExtXDateRange::new("id", FixedOffset::east(8 * HOURS_IN_SECS)
/// .ymd(2010, 2, 19)
/// .and_hms_milli(14, 54, 23, 31));
/// let date_range = ExtXDateRange::new(
/// "id",
/// FixedOffset::east(8 * HOURS_IN_SECS)
/// .ymd(2010, 2, 19)
/// .and_hms_milli(14, 54, 23, 31),
/// );
/// ```
pub fn new<T: ToString>(id: T, start_date: DateTime<FixedOffset>) -> Self {
Self {
@ -100,21 +104,22 @@ impl ExtXDateRange {
/// # Example
/// ```
/// # use hls_m3u8::tags::ExtXDateRange;
/// use hls_m3u8::types::{RequiredVersion, ProtocolVersion};
/// use chrono::{DateTime, FixedOffset};
/// use chrono::offset::TimeZone;
/// use chrono::{DateTime, FixedOffset};
/// use hls_m3u8::types::{ProtocolVersion, RequiredVersion};
///
/// const HOURS_IN_SECS: i32 = 3600; // 1 hour = 3600 seconds
///
/// let date_range = ExtXDateRange::new("id", FixedOffset::east(8 * HOURS_IN_SECS)
/// .ymd(2010, 2, 19)
/// .and_hms_milli(14, 54, 23, 31));
/// let date_range = ExtXDateRange::new(
/// "id",
/// FixedOffset::east(8 * HOURS_IN_SECS)
/// .ymd(2010, 2, 19)
/// .and_hms_milli(14, 54, 23, 31),
/// );
/// assert_eq!(date_range.required_version(), ProtocolVersion::V1);
/// ```
impl RequiredVersion for ExtXDateRange {
fn required_version(&self) -> ProtocolVersion {
ProtocolVersion::V1
}
fn required_version(&self) -> ProtocolVersion { ProtocolVersion::V1 }
}
impl fmt::Display for ExtXDateRange {
@ -198,7 +203,8 @@ impl FromStr for ExtXDateRange {
client_attributes.insert(key.split_at(2).1.to_owned(), value.to_owned());
} else {
// [6.3.1. General Client Responsibilities]
// > ignore any attribute/value pair with an unrecognized AttributeName.
// > ignore any attribute/value pair with an
// unrecognized AttributeName.
}
}
}

View file

@ -25,15 +25,11 @@ impl ExtXDiscontinuity {
}
impl RequiredVersion for ExtXDiscontinuity {
fn required_version(&self) -> ProtocolVersion {
ProtocolVersion::V1
}
fn required_version(&self) -> ProtocolVersion { ProtocolVersion::V1 }
}
impl fmt::Display for ExtXDiscontinuity {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
Self::PREFIX.fmt(f)
}
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { Self::PREFIX.fmt(f) }
}
impl FromStr for ExtXDiscontinuity {
@ -58,9 +54,7 @@ mod test {
}
#[test]
fn test_parser() {
assert_eq!(ExtXDiscontinuity, "#EXT-X-DISCONTINUITY".parse().unwrap())
}
fn test_parser() { assert_eq!(ExtXDiscontinuity, "#EXT-X-DISCONTINUITY".parse().unwrap()) }
#[test]
fn test_required_version() {

View file

@ -70,14 +70,9 @@ impl ExtInf {
///
/// let ext_inf = ExtInf::new(Duration::from_secs(5));
///
/// assert_eq!(
/// ext_inf.duration(),
/// Duration::from_secs(5)
/// );
/// assert_eq!(ext_inf.duration(), Duration::from_secs(5));
/// ```
pub const fn duration(&self) -> Duration {
self.duration
}
pub const fn duration(&self) -> Duration { self.duration }
/// Sets the duration of the associated media segment.
///
@ -90,10 +85,7 @@ impl ExtInf {
///
/// ext_inf.set_duration(Duration::from_secs(10));
///
/// assert_eq!(
/// ext_inf.duration(),
/// Duration::from_secs(10)
/// );
/// assert_eq!(ext_inf.duration(), Duration::from_secs(10));
/// ```
pub fn set_duration(&mut self, value: Duration) -> &mut Self {
self.duration = value;
@ -109,14 +101,9 @@ impl ExtInf {
///
/// let ext_inf = ExtInf::with_title(Duration::from_secs(5), "title");
///
/// assert_eq!(
/// ext_inf.title(),
/// &Some("title".to_string())
/// );
/// assert_eq!(ext_inf.title(), &Some("title".to_string()));
/// ```
pub const fn title(&self) -> &Option<String> {
&self.title
}
pub const fn title(&self) -> &Option<String> { &self.title }
/// Sets the title of the associated media segment.
///
@ -129,10 +116,7 @@ impl ExtInf {
///
/// ext_inf.set_title(Some("better title"));
///
/// assert_eq!(
/// ext_inf.title(),
/// &Some("better title".to_string())
/// );
/// assert_eq!(ext_inf.title(), &Some("better title".to_string()));
/// ```
pub fn set_title<T: ToString>(&mut self, value: Option<T>) -> &mut Self {
self.title = value.map(|v| v.to_string());
@ -198,9 +182,7 @@ impl FromStr for ExtInf {
}
impl From<Duration> for ExtInf {
fn from(value: Duration) -> Self {
Self::new(value)
}
fn from(value: Duration) -> Self { Self::new(value) }
}
#[cfg(test)]

View file

@ -40,10 +40,7 @@ impl ExtXKey {
/// use hls_m3u8::tags::ExtXKey;
/// use hls_m3u8::types::EncryptionMethod;
///
/// let key = ExtXKey::new(
/// EncryptionMethod::Aes128,
/// "https://www.example.com/"
/// );
/// let key = ExtXKey::new(EncryptionMethod::Aes128, "https://www.example.com/");
///
/// assert_eq!(
/// key.to_string(),
@ -62,10 +59,7 @@ impl ExtXKey {
///
/// let key = ExtXKey::empty();
///
/// assert_eq!(
/// key.to_string(),
/// "#EXT-X-KEY:METHOD=NONE"
/// );
/// assert_eq!(key.to_string(), "#EXT-X-KEY:METHOD=NONE");
/// ```
pub const fn empty() -> Self {
Self(DecryptionKey {
@ -87,14 +81,9 @@ impl ExtXKey {
///
/// let key = ExtXKey::empty();
///
/// assert_eq!(
/// key.method() == EncryptionMethod::None,
/// key.is_empty()
/// );
/// assert_eq!(key.method() == EncryptionMethod::None, key.is_empty());
/// ```
pub fn is_empty(&self) -> bool {
self.0.method() == EncryptionMethod::None
}
pub fn is_empty(&self) -> bool { self.0.method() == EncryptionMethod::None }
}
impl FromStr for ExtXKey {
@ -107,23 +96,17 @@ impl FromStr for ExtXKey {
}
impl fmt::Display for ExtXKey {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}{}", Self::PREFIX, self.0)
}
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
}
fn deref(&self) -> &Self::Target { &self.0 }
}
impl DerefMut for ExtXKey {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.0
}
fn deref_mut(&mut self) -> &mut Self::Target { &mut self.0 }
}
#[cfg(test)]

View file

@ -45,20 +45,14 @@ impl ExtXMap {
/// Returns the `URI` that identifies a resource,
/// that contains the media initialization section.
pub const fn uri(&self) -> &String {
&self.uri
}
pub const fn uri(&self) -> &String { &self.uri }
/// Returns the range of the media initialization section.
pub const fn range(&self) -> Option<ByteRange> {
self.range
}
pub const fn range(&self) -> Option<ByteRange> { self.range }
}
impl RequiredVersion for ExtXMap {
fn required_version(&self) -> ProtocolVersion {
ProtocolVersion::V6
}
fn required_version(&self) -> ProtocolVersion { ProtocolVersion::V6 }
}
impl fmt::Display for ExtXMap {
@ -89,7 +83,8 @@ impl FromStr for ExtXMap {
}
_ => {
// [6.3.1. General Client Responsibilities]
// > ignore any attribute/value pair with an unrecognized AttributeName.
// > ignore any attribute/value pair with an unrecognized
// AttributeName.
}
}
}

View file

@ -24,25 +24,22 @@ impl ExtXProgramDateTime {
///
/// # Example
/// ```
/// use hls_m3u8::tags::ExtXProgramDateTime;
/// use chrono::{FixedOffset, TimeZone};
/// use hls_m3u8::tags::ExtXProgramDateTime;
///
/// const HOURS_IN_SECS: i32 = 3600; // 1 hour = 3600 seconds
///
/// let program_date_time = ExtXProgramDateTime::new(
/// FixedOffset::east(8 * HOURS_IN_SECS)
/// .ymd(2010, 2, 19)
/// .and_hms_milli(14, 54, 23, 31)
/// .and_hms_milli(14, 54, 23, 31),
/// );
/// ```
pub const fn new(date_time: DateTime<FixedOffset>) -> Self {
Self(date_time)
}
pub const fn new(date_time: DateTime<FixedOffset>) -> Self { Self(date_time) }
/// Returns the date-time of the first sample of the associated media segment.
pub const fn date_time(&self) -> DateTime<FixedOffset> {
self.0
}
/// Returns the date-time of the first sample of the associated media
/// segment.
pub const fn date_time(&self) -> DateTime<FixedOffset> { self.0 }
/// Sets the date-time of the first sample of the associated media segment.
pub fn set_date_time(&mut self, value: DateTime<FixedOffset>) -> &mut Self {
@ -52,9 +49,7 @@ impl ExtXProgramDateTime {
}
impl RequiredVersion for ExtXProgramDateTime {
fn required_version(&self) -> ProtocolVersion {
ProtocolVersion::V1
}
fn required_version(&self) -> ProtocolVersion { ProtocolVersion::V1 }
}
impl fmt::Display for ExtXProgramDateTime {
@ -78,15 +73,11 @@ impl FromStr for ExtXProgramDateTime {
impl Deref for ExtXProgramDateTime {
type Target = DateTime<FixedOffset>;
fn deref(&self) -> &Self::Target {
&self.0
}
fn deref(&self) -> &Self::Target { &self.0 }
}
impl DerefMut for ExtXProgramDateTime {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.0
}
fn deref_mut(&mut self) -> &mut Self::Target { &mut self.0 }
}
#[cfg(test)]

View file

@ -16,15 +16,11 @@ impl ExtXIndependentSegments {
}
impl RequiredVersion for ExtXIndependentSegments {
fn required_version(&self) -> ProtocolVersion {
ProtocolVersion::V1
}
fn required_version(&self) -> ProtocolVersion { ProtocolVersion::V1 }
}
impl fmt::Display for ExtXIndependentSegments {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
Self::PREFIX.fmt(f)
}
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { Self::PREFIX.fmt(f) }
}
impl FromStr for ExtXIndependentSegments {

View file

@ -61,9 +61,7 @@ impl ExtXStart {
/// let start = ExtXStart::new(20.123456);
/// assert_eq!(start.time_offset(), 20.123456);
/// ```
pub const fn time_offset(&self) -> f64 {
self.time_offset.as_f64()
}
pub const fn time_offset(&self) -> f64 { self.time_offset.as_f64() }
/// Sets the time offset of the media segments in the playlist.
///
@ -82,8 +80,8 @@ impl ExtXStart {
self
}
/// Returns whether clients should not render media stream whose presentation times are
/// prior to the specified time offset.
/// Returns whether clients should not render media stream whose
/// presentation times are prior to the specified time offset.
///
/// # Example
/// ```
@ -91,9 +89,7 @@ impl ExtXStart {
/// let start = ExtXStart::with_precise(20.123456, true);
/// assert_eq!(start.precise(), true);
/// ```
pub const fn precise(&self) -> bool {
self.precise
}
pub const fn precise(&self) -> bool { self.precise }
/// Sets the `precise` flag.
///
@ -114,9 +110,7 @@ impl ExtXStart {
}
impl RequiredVersion for ExtXStart {
fn required_version(&self) -> ProtocolVersion {
ProtocolVersion::V1
}
fn required_version(&self) -> ProtocolVersion { ProtocolVersion::V1 }
}
impl fmt::Display for ExtXStart {
@ -145,7 +139,8 @@ impl FromStr for ExtXStart {
"PRECISE" => precise = (parse_yes_or_no(value))?,
_ => {
// [6.3.1. General Client Responsibilities]
// > ignore any attribute/value pair with an unrecognized AttributeName.
// > ignore any attribute/value pair with an unrecognized
// AttributeName.
}
}
}

View file

@ -22,9 +22,7 @@ impl ByteRange {
/// # use hls_m3u8::types::ByteRange;
/// ByteRange::new(22, Some(12));
/// ```
pub const fn new(length: usize, start: Option<usize>) -> Self {
Self { length, start }
}
pub const fn new(length: usize, start: Option<usize>) -> Self { Self { length, start } }
/// Returns the length of the range.
///
@ -34,9 +32,7 @@ impl ByteRange {
/// #
/// assert_eq!(ByteRange::new(20, Some(3)).length(), 20);
/// ```
pub const fn length(&self) -> usize {
self.length
}
pub const fn length(&self) -> usize { self.length }
/// Sets the length of the range.
///
@ -63,9 +59,7 @@ impl ByteRange {
/// #
/// assert_eq!(ByteRange::new(20, Some(3)).start(), Some(3));
/// ```
pub const fn start(&self) -> Option<usize> {
self.start
}
pub const fn start(&self) -> Option<usize> { self.start }
/// Sets the start of the range.
///

View file

@ -11,8 +11,8 @@ use crate::Error;
/// present in any [`MediaSegment`] in the rendition. For example, an
/// `AC-3 5.1` rendition would have a `CHANNELS="6"` attribute.
///
/// The second parameter identifies the encoding of object-based audio used by the
/// rendition. This parameter is a comma-separated list of Audio
/// The second parameter identifies the encoding of object-based audio used by
/// the rendition. This parameter is a comma-separated list of Audio
/// Object Coding Identifiers. It is optional. An Audio Object
/// Coding Identifier is a string containing characters from the set
/// `[A..Z]`, `[0..9]`, and `'-'`. They are codec-specific. A parameter
@ -25,7 +25,10 @@ use crate::Error;
/// # use hls_m3u8::types::Channels;
/// let mut channels = Channels::new(6);
///
/// assert_eq!(format!("CHANNELS=\"{}\"", channels), "CHANNELS=\"6\"".to_string());
/// assert_eq!(
/// format!("CHANNELS=\"{}\"", channels),
/// "CHANNELS=\"6\"".to_string()
/// );
/// ```
///
/// # Note
@ -64,9 +67,7 @@ impl Channels {
///
/// assert_eq!(channels.first_parameter(), 6);
/// ```
pub const fn first_parameter(&self) -> u64 {
self.first_parameter
}
pub const fn first_parameter(&self) -> u64 { self.first_parameter }
/// Sets the first parameter.
///
@ -91,15 +92,16 @@ impl Channels {
/// let mut channels = Channels::new(3);
/// # assert_eq!(channels.second_parameter(), &None);
///
/// channels.set_second_parameter(Some(vec!["AAC","MP3"]));
/// assert_eq!(channels.second_parameter(), &Some(vec!["AAC".to_string(),"MP3".to_string()]))
/// channels.set_second_parameter(Some(vec!["AAC", "MP3"]));
/// assert_eq!(
/// channels.second_parameter(),
/// &Some(vec!["AAC".to_string(), "MP3".to_string()])
/// )
/// ```
///
/// # Note
/// Currently there is no use for this parameter.
pub const fn second_parameter(&self) -> &Option<Vec<String>> {
&self.second_parameter
}
pub const fn second_parameter(&self) -> &Option<Vec<String>> { &self.second_parameter }
/// Sets the second parameter.
///
@ -109,8 +111,11 @@ impl Channels {
/// let mut channels = Channels::new(3);
/// # assert_eq!(channels.second_parameter(), &None);
///
/// channels.set_second_parameter(Some(vec!["AAC","MP3"]));
/// assert_eq!(channels.second_parameter(), &Some(vec!["AAC".to_string(),"MP3".to_string()]))
/// channels.set_second_parameter(Some(vec!["AAC", "MP3"]));
/// assert_eq!(
/// channels.second_parameter(),
/// &Some(vec!["AAC".to_string(), "MP3".to_string()])
/// )
/// ```
///
/// # Note

View file

@ -20,7 +20,8 @@ impl DecimalFloatingPoint {
/// # Errors
///
/// The given value must have a positive sign and be finite,
/// otherwise this function will return an error that has the kind `ErrorKind::InvalidInput`.
/// otherwise this function will return an error that has the kind
/// `ErrorKind::InvalidInput`.
pub fn new(value: f64) -> crate::Result<Self> {
if value.is_sign_negative() || value.is_infinite() {
return Err(Error::invalid_input());
@ -28,34 +29,26 @@ impl DecimalFloatingPoint {
Ok(Self(value))
}
pub(crate) const fn from_f64_unchecked(value: f64) -> Self {
Self(value)
}
pub(crate) const fn from_f64_unchecked(value: f64) -> Self { Self(value) }
/// Converts [`DecimalFloatingPoint`] to [`f64`].
pub const fn as_f64(self) -> f64 {
self.0
}
pub const fn as_f64(self) -> f64 { self.0 }
}
impl Eq for DecimalFloatingPoint {}
// this trait is implemented manually, so it doesn't construct a [`DecimalFloatingPoint`],
// with a negative value.
// this trait is implemented manually, so it doesn't construct a
// [`DecimalFloatingPoint`], with a negative value.
impl FromStr for DecimalFloatingPoint {
type Err = Error;
fn from_str(input: &str) -> Result<Self, Self::Err> {
Self::new(input.parse()?)
}
fn from_str(input: &str) -> Result<Self, Self::Err> { Self::new(input.parse()?) }
}
impl Deref for DecimalFloatingPoint {
type Target = f64;
fn deref(&self) -> &Self::Target {
&self.0
}
fn deref(&self) -> &Self::Target { &self.0 }
}
impl From<f64> for DecimalFloatingPoint {
@ -72,9 +65,7 @@ impl From<f64> for DecimalFloatingPoint {
}
impl From<f32> for DecimalFloatingPoint {
fn from(value: f32) -> Self {
(value as f64).into()
}
fn from(value: f32) -> Self { (value as f64).into() }
}
#[cfg(test)]

View file

@ -18,14 +18,10 @@ pub(crate) struct DecimalResolution {
impl DecimalResolution {
/// Creates a new [`DecimalResolution`].
pub const fn new(width: usize, height: usize) -> Self {
Self { width, height }
}
pub const fn new(width: usize, height: usize) -> Self { Self { width, height } }
/// Horizontal pixel dimension.
pub const fn width(&self) -> usize {
self.width
}
pub const fn width(&self) -> usize { self.width }
/// Sets Horizontal pixel dimension.
pub fn set_width(&mut self, value: usize) -> &mut Self {
@ -34,9 +30,7 @@ impl DecimalResolution {
}
/// Vertical pixel dimension.
pub const fn height(&self) -> usize {
self.height
}
pub const fn height(&self) -> usize { self.height }
/// Sets Vertical pixel dimension.
pub fn set_height(&mut self, value: usize) -> &mut Self {
@ -47,9 +41,7 @@ impl DecimalResolution {
/// [`DecimalResolution`] can be constructed from a tuple; `(width, height)`.
impl From<(usize, usize)> for DecimalResolution {
fn from(value: (usize, usize)) -> Self {
DecimalResolution::new(value.0, value.1)
}
fn from(value: (usize, usize)) -> Self { DecimalResolution::new(value.0, value.1) }
}
impl FromStr for DecimalResolution {

View file

@ -13,7 +13,8 @@ use crate::Error;
#[derive(Builder, Debug, Clone, PartialEq, Eq, Hash)]
#[builder(setter(into), build_fn(validate = "Self::validate"))]
/// [`DecryptionKey`] contains data, that is shared between [`ExtXSessionKey`] and [`ExtXKey`].
/// [`DecryptionKey`] contains data, that is shared between [`ExtXSessionKey`]
/// and [`ExtXKey`].
///
/// [`ExtXSessionKey`]: crate::tags::ExtXSessionKey
/// [`ExtXKey`]: crate::tags::ExtXKey
@ -52,10 +53,7 @@ impl DecryptionKey {
/// # use hls_m3u8::types::DecryptionKey;
/// use hls_m3u8::types::EncryptionMethod;
///
/// let key = DecryptionKey::new(
/// EncryptionMethod::Aes128,
/// "https://www.example.com/"
/// );
/// let key = DecryptionKey::new(EncryptionMethod::Aes128, "https://www.example.com/");
/// ```
pub fn new<T: ToString>(method: EncryptionMethod, uri: T) -> Self {
Self {
@ -74,24 +72,14 @@ impl DecryptionKey {
/// # use hls_m3u8::types::DecryptionKey;
/// use hls_m3u8::types::EncryptionMethod;
///
/// let key = DecryptionKey::new(
/// EncryptionMethod::Aes128,
/// "https://www.example.com/"
/// );
/// let key = DecryptionKey::new(EncryptionMethod::Aes128, "https://www.example.com/");
///
/// assert_eq!(
/// key.method(),
/// EncryptionMethod::Aes128
/// );
/// assert_eq!(key.method(), EncryptionMethod::Aes128);
/// ```
pub const fn method(&self) -> EncryptionMethod {
self.method
}
pub const fn method(&self) -> EncryptionMethod { self.method }
/// Returns a Builder to build a [DecryptionKey].
pub fn builder() -> DecryptionKeyBuilder {
DecryptionKeyBuilder::default()
}
pub fn builder() -> DecryptionKeyBuilder { DecryptionKeyBuilder::default() }
/// Sets the [EncryptionMethod].
///
@ -100,10 +88,7 @@ impl DecryptionKey {
/// # use hls_m3u8::types::DecryptionKey;
/// use hls_m3u8::types::EncryptionMethod;
///
/// let mut key = DecryptionKey::new(
/// EncryptionMethod::Aes128,
/// "https://www.example.com/"
/// );
/// let mut key = DecryptionKey::new(EncryptionMethod::Aes128, "https://www.example.com/");
///
/// key.set_method(EncryptionMethod::SampleAes);
///
@ -127,19 +112,11 @@ impl DecryptionKey {
/// # use hls_m3u8::types::DecryptionKey;
/// use hls_m3u8::types::EncryptionMethod;
///
/// let key = DecryptionKey::new(
/// EncryptionMethod::Aes128,
/// "https://www.example.com/"
/// );
/// let key = DecryptionKey::new(EncryptionMethod::Aes128, "https://www.example.com/");
///
/// assert_eq!(
/// key.uri(),
/// &Some("https://www.example.com/".to_string())
/// );
/// assert_eq!(key.uri(), &Some("https://www.example.com/".to_string()));
/// ```
pub const fn uri(&self) -> &Option<String> {
&self.uri
}
pub const fn uri(&self) -> &Option<String> { &self.uri }
/// Sets the `URI` attribute.
///
@ -151,10 +128,7 @@ impl DecryptionKey {
/// # use hls_m3u8::types::DecryptionKey;
/// use hls_m3u8::types::EncryptionMethod;
///
/// let mut key = DecryptionKey::new(
/// EncryptionMethod::Aes128,
/// "https://www.example.com/"
/// );
/// let mut key = DecryptionKey::new(EncryptionMethod::Aes128, "https://www.example.com/");
///
/// key.set_uri(Some("http://www.google.com/"));
///
@ -175,15 +149,10 @@ impl DecryptionKey {
/// # use hls_m3u8::types::DecryptionKey;
/// use hls_m3u8::types::EncryptionMethod;
///
/// let mut key = DecryptionKey::new(
/// EncryptionMethod::Aes128,
/// "https://www.example.com/"
/// );
/// let mut key = DecryptionKey::new(EncryptionMethod::Aes128, "https://www.example.com/");
///
/// # assert_eq!(key.iv(), None);
/// key.set_iv(Some([
/// 1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7
/// ]));
/// key.set_iv(Some([1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7]));
///
/// assert_eq!(
/// key.iv(),
@ -205,18 +174,14 @@ impl DecryptionKey {
/// # use hls_m3u8::types::DecryptionKey;
/// use hls_m3u8::types::EncryptionMethod;
///
/// let mut key = DecryptionKey::new(
/// EncryptionMethod::Aes128,
/// "https://www.example.com/"
/// );
/// let mut key = DecryptionKey::new(EncryptionMethod::Aes128, "https://www.example.com/");
///
/// key.set_iv(Some([
/// 1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7
/// ]));
/// key.set_iv(Some([1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7]));
///
/// assert_eq!(
/// key.to_string(),
/// "METHOD=AES-128,URI=\"https://www.example.com/\",IV=0x01020304050607080901020304050607".to_string()
/// "METHOD=AES-128,URI=\"https://www.example.com/\",IV=0x01020304050607080901020304050607"
/// .to_string()
/// );
/// ```
pub fn set_iv<T>(&mut self, value: Option<T>) -> &mut Self
@ -233,42 +198,28 @@ impl DecryptionKey {
/// # Example
/// ```
/// # use hls_m3u8::types::DecryptionKey;
/// use hls_m3u8::types::{KeyFormat, EncryptionMethod};
/// use hls_m3u8::types::{EncryptionMethod, KeyFormat};
///
/// let mut key = DecryptionKey::new(
/// EncryptionMethod::Aes128,
/// "https://www.example.com/"
/// );
/// let mut key = DecryptionKey::new(EncryptionMethod::Aes128, "https://www.example.com/");
///
/// key.set_key_format(Some(KeyFormat::Identity));
///
/// assert_eq!(
/// key.key_format(),
/// Some(KeyFormat::Identity)
/// );
/// assert_eq!(key.key_format(), Some(KeyFormat::Identity));
/// ```
pub const fn key_format(&self) -> Option<KeyFormat> {
self.key_format
}
pub const fn key_format(&self) -> Option<KeyFormat> { self.key_format }
/// Sets the [KeyFormat] attribute.
///
/// # Example
/// ```
/// # use hls_m3u8::types::DecryptionKey;
/// use hls_m3u8::types::{KeyFormat, EncryptionMethod};
/// use hls_m3u8::types::{EncryptionMethod, KeyFormat};
///
/// let mut key = DecryptionKey::new(
/// EncryptionMethod::Aes128,
/// "https://www.example.com/"
/// );
/// let mut key = DecryptionKey::new(EncryptionMethod::Aes128, "https://www.example.com/");
///
/// key.set_key_format(Some(KeyFormat::Identity));
///
/// assert_eq!(
/// key.key_format(),
/// Some(KeyFormat::Identity)
/// );
/// assert_eq!(key.key_format(), Some(KeyFormat::Identity));
/// ```
pub fn set_key_format<T: Into<KeyFormat>>(&mut self, value: Option<T>) -> &mut Self {
self.key_format = value.map(|v| v.into());
@ -280,12 +231,9 @@ impl DecryptionKey {
/// # Example
/// ```
/// # use hls_m3u8::types::DecryptionKey;
/// use hls_m3u8::types::{KeyFormatVersions, EncryptionMethod};
/// use hls_m3u8::types::{EncryptionMethod, KeyFormatVersions};
///
/// let mut key = DecryptionKey::new(
/// EncryptionMethod::Aes128,
/// "https://www.example.com/"
/// );
/// let mut key = DecryptionKey::new(EncryptionMethod::Aes128, "https://www.example.com/");
///
/// key.set_key_format_versions(Some(vec![1, 2, 3, 4, 5]));
///
@ -305,16 +253,14 @@ impl DecryptionKey {
/// # use hls_m3u8::types::DecryptionKey;
/// use hls_m3u8::types::EncryptionMethod;
///
/// let mut key = DecryptionKey::new(
/// EncryptionMethod::Aes128,
/// "https://www.example.com/"
/// );
/// let mut key = DecryptionKey::new(EncryptionMethod::Aes128, "https://www.example.com/");
///
/// key.set_key_format_versions(Some(vec![1, 2, 3, 4, 5]));
///
/// assert_eq!(
/// key.to_string(),
/// "METHOD=AES-128,URI=\"https://www.example.com/\",KEYFORMATVERSIONS=\"1/2/3/4/5\"".to_string()
/// "METHOD=AES-128,URI=\"https://www.example.com/\",KEYFORMATVERSIONS=\"1/2/3/4/5\""
/// .to_string()
/// );
/// ```
pub fn set_key_format_versions<T: Into<KeyFormatVersions>>(
@ -357,7 +303,8 @@ impl FromStr for DecryptionKey {
"KEYFORMATVERSIONS" => key_format_versions = Some(value.parse()?),
_ => {
// [6.3.1. General Client Responsibilities]
// > ignore any attribute/value pair with an unrecognized AttributeName.
// > ignore any attribute/value pair with an unrecognized
// AttributeName.
}
}
}

View file

@ -14,28 +14,21 @@ pub struct InitializationVector(pub [u8; 16]);
impl InitializationVector {
/// Converts the [InitializationVector] to a slice.
pub const fn to_slice(&self) -> [u8; 16] {
self.0
}
pub const fn to_slice(&self) -> [u8; 16] { self.0 }
}
impl From<[u8; 16]> for InitializationVector {
fn from(value: [u8; 16]) -> Self {
Self(value)
}
fn from(value: [u8; 16]) -> Self { Self(value) }
}
impl Deref for InitializationVector {
type Target = [u8];
fn deref(&self) -> &Self::Target {
&self.0
}
fn deref(&self) -> &Self::Target { &self.0 }
}
impl AsRef<[u8]> for InitializationVector {
fn as_ref(&self) -> &[u8] {
&self.0
}
fn as_ref(&self) -> &[u8] { &self.0 }
}
impl fmt::Display for InitializationVector {

View file

@ -14,9 +14,7 @@ pub enum KeyFormat {
}
impl Default for KeyFormat {
fn default() -> Self {
Self::Identity
}
fn default() -> Self { Self::Identity }
}
impl FromStr for KeyFormat {
@ -30,15 +28,11 @@ impl FromStr for KeyFormat {
}
impl fmt::Display for KeyFormat {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", quote("identity"))
}
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{}", quote("identity")) }
}
impl RequiredVersion for KeyFormat {
fn required_version(&self) -> ProtocolVersion {
ProtocolVersion::V5
}
fn required_version(&self) -> ProtocolVersion { ProtocolVersion::V5 }
}
#[cfg(test)]

View file

@ -15,16 +15,12 @@ use crate::Error;
pub struct KeyFormatVersions(Vec<usize>);
impl Default for KeyFormatVersions {
fn default() -> Self {
Self(vec![1])
}
fn default() -> Self { Self(vec![1]) }
}
impl KeyFormatVersions {
/// Makes a new [`KeyFormatVersions`].
pub fn new() -> Self {
Self::default()
}
pub fn new() -> Self { Self::default() }
/// Add a value to the [`KeyFormatVersions`].
pub fn push(&mut self, value: usize) {
@ -35,30 +31,23 @@ impl KeyFormatVersions {
}
}
/// Returns `true`, if [`KeyFormatVersions`] has the default value of `vec![1]`.
pub fn is_default(&self) -> bool {
self.0 == vec![1] && self.0.len() == 1 || self.0.is_empty()
}
/// Returns `true`, if [`KeyFormatVersions`] has the default value of
/// `vec![1]`.
pub fn is_default(&self) -> bool { self.0 == vec![1] && self.0.len() == 1 || self.0.is_empty() }
}
impl Deref for KeyFormatVersions {
type Target = Vec<usize>;
fn deref(&self) -> &Self::Target {
&self.0
}
fn deref(&self) -> &Self::Target { &self.0 }
}
impl DerefMut for KeyFormatVersions {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.0
}
fn deref_mut(&mut self) -> &mut Self::Target { &mut self.0 }
}
impl RequiredVersion for KeyFormatVersions {
fn required_version(&self) -> ProtocolVersion {
ProtocolVersion::V5
}
fn required_version(&self) -> ProtocolVersion { ProtocolVersion::V5 }
}
impl FromStr for KeyFormatVersions {
@ -100,9 +89,7 @@ impl fmt::Display for KeyFormatVersions {
}
impl<T: Into<Vec<usize>>> From<T> for KeyFormatVersions {
fn from(value: T) -> Self {
Self(value.into())
}
fn from(value: T) -> Self { Self(value.into()) }
}
#[cfg(test)]

View file

@ -54,9 +54,7 @@ impl ProtocolVersion {
/// # use hls_m3u8::types::ProtocolVersion;
/// assert_eq!(ProtocolVersion::latest(), ProtocolVersion::V7);
/// ```
pub const fn latest() -> Self {
Self::V7
}
pub const fn latest() -> Self { Self::V7 }
}
impl fmt::Display for ProtocolVersion {
@ -93,9 +91,7 @@ impl FromStr for ProtocolVersion {
}
impl Default for ProtocolVersion {
fn default() -> Self {
Self::V1
}
fn default() -> Self { Self::V1 }
}
#[cfg(test)]

View file

@ -21,22 +21,16 @@ impl SignedDecimalFloatingPoint {
Self(value)
}
pub(crate) const fn from_f64_unchecked(value: f64) -> Self {
Self(value)
}
pub(crate) const fn from_f64_unchecked(value: f64) -> Self { Self(value) }
/// Converts [DecimalFloatingPoint] to [f64].
pub const fn as_f64(self) -> f64 {
self.0
}
pub const fn as_f64(self) -> f64 { self.0 }
}
impl Deref for SignedDecimalFloatingPoint {
type Target = f64;
fn deref(&self) -> &Self::Target {
&self.0
}
fn deref(&self) -> &Self::Target { &self.0 }
}
impl Eq for SignedDecimalFloatingPoint {}
@ -82,9 +76,7 @@ mod tests {
#[test]
#[should_panic]
fn test_new_panic() {
SignedDecimalFloatingPoint::new(::std::f64::INFINITY);
}
fn test_new_panic() { SignedDecimalFloatingPoint::new(::std::f64::INFINITY); }
#[test]
fn test_parser() {

View file

@ -47,9 +47,7 @@ impl StreamInf {
/// let stream = StreamInf::new(20);
/// assert_eq!(stream.bandwidth(), 20);
/// ```
pub const fn bandwidth(&self) -> u64 {
self.bandwidth
}
pub const fn bandwidth(&self) -> u64 { self.bandwidth }
/// Sets the peak segment bit rate of the variant stream.
///
@ -76,9 +74,7 @@ impl StreamInf {
/// let stream = StreamInf::new(20);
/// assert_eq!(stream.video(), &None);
/// ```
pub const fn video(&self) -> &Option<String> {
&self.video
}
pub const fn video(&self) -> &Option<String> { &self.video }
/// Sets the group identifier for the video in the variant stream.
///
@ -105,9 +101,7 @@ impl StreamInf {
/// let stream = StreamInf::new(20);
/// assert_eq!(stream.average_bandwidth(), None);
/// ```
pub const fn average_bandwidth(&self) -> Option<u64> {
self.average_bandwidth
}
pub const fn average_bandwidth(&self) -> Option<u64> { self.average_bandwidth }
/// Sets the average segment bit rate of the variant stream.
///
@ -125,7 +119,8 @@ impl StreamInf {
self
}
/// A string that represents the list of codec types contained the variant stream.
/// A string that represents the list of codec types contained the variant
/// stream.
///
/// # Examples
/// ```
@ -134,11 +129,10 @@ impl StreamInf {
/// let stream = StreamInf::new(20);
/// assert_eq!(stream.codecs(), &None);
/// ```
pub const fn codecs(&self) -> &Option<String> {
&self.codecs
}
pub const fn codecs(&self) -> &Option<String> { &self.codecs }
/// A string that represents the list of codec types contained the variant stream.
/// A string that represents the list of codec types contained the variant
/// stream.
///
/// # Examples
/// ```
@ -203,9 +197,7 @@ impl StreamInf {
/// let stream = StreamInf::new(20);
/// assert_eq!(stream.hdcp_level(), None);
/// ```
pub const fn hdcp_level(&self) -> Option<HdcpLevel> {
self.hdcp_level
}
pub const fn hdcp_level(&self) -> Option<HdcpLevel> { self.hdcp_level }
/// The HDCP level of the variant stream.
///
@ -268,7 +260,8 @@ impl FromStr for StreamInf {
"VIDEO" => video = Some(unquote(value)),
_ => {
// [6.3.1. General Client Responsibilities]
// > ignore any attribute/value pair with an unrecognized AttributeName.
// > ignore any attribute/value pair with an unrecognized
// AttributeName.
}
}
}

View file

@ -47,17 +47,17 @@ pub(crate) fn unquote<T: ToString>(value: T) -> String {
/// Puts a string inside quotes.
pub(crate) fn quote<T: ToString>(value: T) -> String {
// the replace is for the case, that quote is called on an already quoted string, which could
// cause problems!
// the replace is for the case, that quote is called on an already quoted
// string, which could cause problems!
format!("\"{}\"", value.to_string().replace("\"", ""))
}
/// Checks, if the given tag is at the start of the input. If this is the case, it will remove it
/// and return the rest of the input.
/// Checks, if the given tag is at the start of the input. If this is the case,
/// it will remove it and return the rest of the input.
///
/// # Error
/// This function will return `Error::MissingTag`, if the input doesn't start with the tag, that
/// has been passed to this function.
/// This function will return `Error::MissingTag`, if the input doesn't start
/// with the tag, that has been passed to this function.
pub(crate) fn tag<T>(input: &str, tag: T) -> crate::Result<&str>
where
T: AsRef<str>,