From 9273e6c16cbaa342f335c425da30d289491a0084 Mon Sep 17 00:00:00 2001 From: Luro02 <24826124+Luro02@users.noreply.github.com> Date: Mon, 24 Feb 2020 16:30:43 +0100 Subject: [PATCH] add must_use attributes --- src/lib.rs | 1 - src/master_playlist.rs | 2 ++ src/media_playlist.rs | 2 ++ src/tags/basic/version.rs | 2 ++ src/tags/master_playlist/media.rs | 2 ++ src/tags/master_playlist/session_data.rs | 3 +++ src/tags/master_playlist/session_key.rs | 1 + src/tags/master_playlist/variant_stream.rs | 1 + src/tags/media_playlist/discontinuity_sequence.rs | 1 + src/tags/media_playlist/media_sequence.rs | 2 ++ src/tags/media_playlist/target_duration.rs | 2 ++ src/tags/media_segment/date_range.rs | 2 ++ src/tags/media_segment/inf.rs | 4 ++++ src/tags/media_segment/program_date_time.rs | 2 ++ src/types/float.rs | 2 ++ src/types/protocol_version.rs | 2 ++ src/types/stream_data.rs | 2 ++ src/types/ufloat.rs | 2 ++ 18 files changed, 34 insertions(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 3659b68..c15d512 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -6,7 +6,6 @@ )] #![allow( clippy::multiple_crate_versions, - clippy::must_use_candidate, clippy::module_name_repetitions, clippy::default_trait_access )] diff --git a/src/master_playlist.rs b/src/master_playlist.rs index 1376e10..4499db2 100644 --- a/src/master_playlist.rs +++ b/src/master_playlist.rs @@ -111,6 +111,8 @@ impl MasterPlaylist { /// .build()?; /// # Ok::<(), Box>(()) /// ``` + #[must_use] + #[inline] pub fn builder() -> MasterPlaylistBuilder { MasterPlaylistBuilder::default() } } diff --git a/src/media_playlist.rs b/src/media_playlist.rs index f7855ed..fdd167d 100644 --- a/src/media_playlist.rs +++ b/src/media_playlist.rs @@ -205,6 +205,8 @@ impl RequiredVersion for MediaPlaylistBuilder { impl MediaPlaylist { /// Returns a builder for [`MediaPlaylist`]. + #[must_use] + #[inline] pub fn builder() -> MediaPlaylistBuilder { MediaPlaylistBuilder::default() } } diff --git a/src/tags/basic/version.rs b/src/tags/basic/version.rs index 3b2e3cf..e758f01 100644 --- a/src/tags/basic/version.rs +++ b/src/tags/basic/version.rs @@ -27,6 +27,7 @@ impl ExtXVersion { /// /// let version = ExtXVersion::new(ProtocolVersion::V2); /// ``` + #[must_use] pub const fn new(version: ProtocolVersion) -> Self { Self(version) } /// Returns the underlying [`ProtocolVersion`]. @@ -42,6 +43,7 @@ impl ExtXVersion { /// ProtocolVersion::V6 /// ); /// ``` + #[must_use] pub const fn version(self) -> ProtocolVersion { self.0 } } diff --git a/src/tags/master_playlist/media.rs b/src/tags/master_playlist/media.rs index e30b079..e59a00f 100644 --- a/src/tags/master_playlist/media.rs +++ b/src/tags/master_playlist/media.rs @@ -191,6 +191,7 @@ impl ExtXMedia { pub(crate) const PREFIX: &'static str = "#EXT-X-MEDIA:"; /// Makes a new [`ExtXMedia`] tag. + #[must_use] pub fn new(media_type: MediaType, group_id: T, name: K) -> Self where T: Into, @@ -213,6 +214,7 @@ impl ExtXMedia { } /// Returns a builder for [`ExtXMedia`]. + #[must_use] pub fn builder() -> ExtXMediaBuilder { ExtXMediaBuilder::default() } } diff --git a/src/tags/master_playlist/session_data.rs b/src/tags/master_playlist/session_data.rs index 4c23fd4..8d9058c 100644 --- a/src/tags/master_playlist/session_data.rs +++ b/src/tags/master_playlist/session_data.rs @@ -140,6 +140,7 @@ impl ExtXSessionData { /// SessionData::Uri("https://www.example.com/".to_string()), /// ); /// ``` + #[must_use] pub fn new>(data_id: T, data: SessionData) -> Self { Self { data_id: data_id.into(), @@ -163,6 +164,7 @@ impl ExtXSessionData { /// .build()?; /// # Ok::<(), Box>(()) /// ``` + #[must_use] pub fn builder() -> ExtXSessionDataBuilder { ExtXSessionDataBuilder::default() } /// Makes a new [`ExtXSessionData`] tag, with the given language. @@ -179,6 +181,7 @@ impl ExtXSessionData { /// "en", /// ); /// ``` + #[must_use] pub fn with_language(data_id: T, data: SessionData, language: K) -> Self where T: Into, diff --git a/src/tags/master_playlist/session_key.rs b/src/tags/master_playlist/session_key.rs index ce93168..973911f 100644 --- a/src/tags/master_playlist/session_key.rs +++ b/src/tags/master_playlist/session_key.rs @@ -45,6 +45,7 @@ impl ExtXSessionKey { /// "https://www.example.com/", /// )); /// ``` + #[must_use] pub fn new(inner: ExtXKey) -> Self { if inner.method() == EncryptionMethod::None { panic!("the encryption method should never be `None`"); diff --git a/src/tags/master_playlist/variant_stream.rs b/src/tags/master_playlist/variant_stream.rs index 9723b08..bc2dde4 100644 --- a/src/tags/master_playlist/variant_stream.rs +++ b/src/tags/master_playlist/variant_stream.rs @@ -201,6 +201,7 @@ impl VariantStream { /// .unwrap(), /// )); /// ``` + #[must_use] pub fn is_associated(&self, media: &ExtXMedia) -> bool { match &self { Self::ExtXIFrame { stream_data, .. } => { diff --git a/src/tags/media_playlist/discontinuity_sequence.rs b/src/tags/media_playlist/discontinuity_sequence.rs index a0a0349..96972ed 100644 --- a/src/tags/media_playlist/discontinuity_sequence.rs +++ b/src/tags/media_playlist/discontinuity_sequence.rs @@ -49,6 +49,7 @@ impl ExtXDiscontinuitySequence { /// # use hls_m3u8::tags::ExtXDiscontinuitySequence; /// let discontinuity_sequence = ExtXDiscontinuitySequence::new(5); /// ``` + #[must_use] pub const fn new(seq_num: u64) -> Self { Self { seq_num } } } diff --git a/src/tags/media_playlist/media_sequence.rs b/src/tags/media_playlist/media_sequence.rs index c7cb4ca..224ca88 100644 --- a/src/tags/media_playlist/media_sequence.rs +++ b/src/tags/media_playlist/media_sequence.rs @@ -27,6 +27,7 @@ impl ExtXMediaSequence { /// # use hls_m3u8::tags::ExtXMediaSequence; /// let media_sequence = ExtXMediaSequence::new(5); /// ``` + #[must_use] pub const fn new(seq_num: u64) -> Self { Self(seq_num) } /// Returns the sequence number of the first media segment, @@ -40,6 +41,7 @@ impl ExtXMediaSequence { /// /// assert_eq!(media_sequence.seq_num(), 5); /// ``` + #[must_use] pub const fn seq_num(self) -> u64 { self.0 } /// Sets the sequence number. diff --git a/src/tags/media_playlist/target_duration.rs b/src/tags/media_playlist/target_duration.rs index aec2ee4..9ef6e3c 100644 --- a/src/tags/media_playlist/target_duration.rs +++ b/src/tags/media_playlist/target_duration.rs @@ -36,6 +36,7 @@ impl ExtXTargetDuration { /// # Note /// /// The nanoseconds part of the [`Duration`] will be discarded. + #[must_use] pub const fn new(duration: Duration) -> Self { Self(Duration::from_secs(duration.as_secs())) } /// Returns the maximum media segment duration. @@ -50,6 +51,7 @@ impl ExtXTargetDuration { /// /// assert_eq!(target_duration.duration(), Duration::from_secs(2)); /// ``` + #[must_use] pub const fn duration(&self) -> Duration { self.0 } } diff --git a/src/tags/media_segment/date_range.rs b/src/tags/media_segment/date_range.rs index 3d0f129..337322b 100644 --- a/src/tags/media_segment/date_range.rs +++ b/src/tags/media_segment/date_range.rs @@ -160,6 +160,7 @@ impl ExtXDateRange { /// .and_hms_milli(14, 54, 23, 31), /// ); /// ``` + #[must_use] pub fn new>(id: T, start_date: DateTime) -> Self { Self { id: id.into(), @@ -177,6 +178,7 @@ impl ExtXDateRange { } /// Returns a builder for [`ExtXDateRange`]. + #[must_use] pub fn builder() -> ExtXDateRangeBuilder { ExtXDateRangeBuilder::default() } } diff --git a/src/tags/media_segment/inf.rs b/src/tags/media_segment/inf.rs index 89eb958..7703e62 100644 --- a/src/tags/media_segment/inf.rs +++ b/src/tags/media_segment/inf.rs @@ -32,6 +32,7 @@ impl ExtInf { /// /// let ext_inf = ExtInf::new(Duration::from_secs(5)); /// ``` + #[must_use] pub const fn new(duration: Duration) -> Self { Self { duration, @@ -49,6 +50,7 @@ impl ExtInf { /// /// let ext_inf = ExtInf::with_title(Duration::from_secs(5), "title"); /// ``` + #[must_use] pub fn with_title>(duration: Duration, title: T) -> Self { Self { duration, @@ -68,6 +70,7 @@ impl ExtInf { /// /// assert_eq!(ext_inf.duration(), Duration::from_secs(5)); /// ``` + #[must_use] pub const fn duration(&self) -> Duration { self.duration } /// Sets the duration of the associated media segment. @@ -101,6 +104,7 @@ impl ExtInf { /// /// assert_eq!(ext_inf.title(), &Some("title".to_string())); /// ``` + #[must_use] pub const fn title(&self) -> &Option { &self.title } /// Sets the title of the associated media segment. diff --git a/src/tags/media_segment/program_date_time.rs b/src/tags/media_segment/program_date_time.rs index bb68f37..36caca7 100644 --- a/src/tags/media_segment/program_date_time.rs +++ b/src/tags/media_segment/program_date_time.rs @@ -38,6 +38,7 @@ impl ExtXProgramDateTime { /// .and_hms_milli(14, 54, 23, 31), /// ); /// ``` + #[must_use] pub const fn new(date_time: DateTime) -> Self { Self(date_time) } /// Returns the date-time of the first sample of the associated media @@ -64,6 +65,7 @@ impl ExtXProgramDateTime { /// .and_hms_milli(14, 54, 23, 31) /// ); /// ``` + #[must_use] pub const fn date_time(&self) -> DateTime { self.0 } /// Sets the date-time of the first sample of the associated media segment. diff --git a/src/types/float.rs b/src/types/float.rs index 7a1d262..b74b607 100644 --- a/src/types/float.rs +++ b/src/types/float.rs @@ -39,6 +39,7 @@ impl Float { /// ``` /// /// [`NaN`]: core::f32::NAN + #[must_use] pub fn new(float: f32) -> Self { if float.is_infinite() { panic!("float must be finite: `{}`", float); @@ -59,6 +60,7 @@ impl Float { /// # use hls_m3u8::types::Float; /// assert_eq!(Float::new(1.1_f32).as_f32(), 1.1_f32); /// ``` + #[must_use] pub const fn as_f32(self) -> f32 { self.0 } } diff --git a/src/types/protocol_version.rs b/src/types/protocol_version.rs index 114d5e8..21f7471 100644 --- a/src/types/protocol_version.rs +++ b/src/types/protocol_version.rs @@ -28,6 +28,8 @@ impl ProtocolVersion { /// # use hls_m3u8::types::ProtocolVersion; /// assert_eq!(ProtocolVersion::latest(), ProtocolVersion::V7); /// ``` + #[must_use] + #[inline] pub const fn latest() -> Self { Self::V7 } } diff --git a/src/types/stream_data.rs b/src/types/stream_data.rs index 624fff9..516c513 100644 --- a/src/types/stream_data.rs +++ b/src/types/stream_data.rs @@ -223,6 +223,7 @@ impl StreamData { /// # /// let stream = StreamData::new(20); /// ``` + #[must_use] pub const fn new(bandwidth: u64) -> Self { Self { bandwidth, @@ -251,6 +252,7 @@ impl StreamData { /// .build()?; /// # Ok::<(), Box>(()) /// ``` + #[must_use] pub fn builder() -> StreamDataBuilder { StreamDataBuilder::default() } } diff --git a/src/types/ufloat.rs b/src/types/ufloat.rs index 36da75a..aadf249 100644 --- a/src/types/ufloat.rs +++ b/src/types/ufloat.rs @@ -38,6 +38,7 @@ impl UFloat { /// ``` /// /// [`NaN`]: core::f32::NAN + #[must_use] pub fn new(float: f32) -> Self { if float.is_infinite() { panic!("float must be finite: `{}`", float); @@ -62,6 +63,7 @@ impl UFloat { /// # use hls_m3u8::types::UFloat; /// assert_eq!(UFloat::new(1.1_f32).as_f32(), 1.1_f32); /// ``` + #[must_use] pub const fn as_f32(self) -> f32 { self.0 } }