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

add must_use attributes

This commit is contained in:
Luro02 2020-02-24 16:30:43 +01:00
parent f7d81a55c9
commit 9273e6c16c
No known key found for this signature in database
GPG key ID: B66FD4F74501A9CF
18 changed files with 34 additions and 1 deletions

View file

@ -6,7 +6,6 @@
)] )]
#![allow( #![allow(
clippy::multiple_crate_versions, clippy::multiple_crate_versions,
clippy::must_use_candidate,
clippy::module_name_repetitions, clippy::module_name_repetitions,
clippy::default_trait_access clippy::default_trait_access
)] )]

View file

@ -111,6 +111,8 @@ impl MasterPlaylist {
/// .build()?; /// .build()?;
/// # Ok::<(), Box<dyn ::std::error::Error>>(()) /// # Ok::<(), Box<dyn ::std::error::Error>>(())
/// ``` /// ```
#[must_use]
#[inline]
pub fn builder() -> MasterPlaylistBuilder { MasterPlaylistBuilder::default() } pub fn builder() -> MasterPlaylistBuilder { MasterPlaylistBuilder::default() }
} }

View file

@ -205,6 +205,8 @@ impl RequiredVersion for MediaPlaylistBuilder {
impl MediaPlaylist { impl MediaPlaylist {
/// Returns a builder for [`MediaPlaylist`]. /// Returns a builder for [`MediaPlaylist`].
#[must_use]
#[inline]
pub fn builder() -> MediaPlaylistBuilder { MediaPlaylistBuilder::default() } pub fn builder() -> MediaPlaylistBuilder { MediaPlaylistBuilder::default() }
} }

View file

@ -27,6 +27,7 @@ impl ExtXVersion {
/// ///
/// let version = ExtXVersion::new(ProtocolVersion::V2); /// let version = ExtXVersion::new(ProtocolVersion::V2);
/// ``` /// ```
#[must_use]
pub const fn new(version: ProtocolVersion) -> Self { Self(version) } pub const fn new(version: ProtocolVersion) -> Self { Self(version) }
/// Returns the underlying [`ProtocolVersion`]. /// Returns the underlying [`ProtocolVersion`].
@ -42,6 +43,7 @@ impl ExtXVersion {
/// ProtocolVersion::V6 /// ProtocolVersion::V6
/// ); /// );
/// ``` /// ```
#[must_use]
pub const fn version(self) -> ProtocolVersion { self.0 } pub const fn version(self) -> ProtocolVersion { self.0 }
} }

View file

@ -191,6 +191,7 @@ impl ExtXMedia {
pub(crate) const PREFIX: &'static str = "#EXT-X-MEDIA:"; pub(crate) const PREFIX: &'static str = "#EXT-X-MEDIA:";
/// Makes a new [`ExtXMedia`] tag. /// Makes a new [`ExtXMedia`] tag.
#[must_use]
pub fn new<T, K>(media_type: MediaType, group_id: T, name: K) -> Self pub fn new<T, K>(media_type: MediaType, group_id: T, name: K) -> Self
where where
T: Into<String>, T: Into<String>,
@ -213,6 +214,7 @@ impl ExtXMedia {
} }
/// Returns a builder for [`ExtXMedia`]. /// Returns a builder for [`ExtXMedia`].
#[must_use]
pub fn builder() -> ExtXMediaBuilder { ExtXMediaBuilder::default() } pub fn builder() -> ExtXMediaBuilder { ExtXMediaBuilder::default() }
} }

View file

@ -140,6 +140,7 @@ impl ExtXSessionData {
/// SessionData::Uri("https://www.example.com/".to_string()), /// SessionData::Uri("https://www.example.com/".to_string()),
/// ); /// );
/// ``` /// ```
#[must_use]
pub fn new<T: Into<String>>(data_id: T, data: SessionData) -> Self { pub fn new<T: Into<String>>(data_id: T, data: SessionData) -> Self {
Self { Self {
data_id: data_id.into(), data_id: data_id.into(),
@ -163,6 +164,7 @@ impl ExtXSessionData {
/// .build()?; /// .build()?;
/// # Ok::<(), Box<dyn ::std::error::Error>>(()) /// # Ok::<(), Box<dyn ::std::error::Error>>(())
/// ``` /// ```
#[must_use]
pub fn builder() -> ExtXSessionDataBuilder { ExtXSessionDataBuilder::default() } pub fn builder() -> ExtXSessionDataBuilder { ExtXSessionDataBuilder::default() }
/// Makes a new [`ExtXSessionData`] tag, with the given language. /// Makes a new [`ExtXSessionData`] tag, with the given language.
@ -179,6 +181,7 @@ impl ExtXSessionData {
/// "en", /// "en",
/// ); /// );
/// ``` /// ```
#[must_use]
pub fn with_language<T, K>(data_id: T, data: SessionData, language: K) -> Self pub fn with_language<T, K>(data_id: T, data: SessionData, language: K) -> Self
where where
T: Into<String>, T: Into<String>,

View file

@ -45,6 +45,7 @@ impl ExtXSessionKey {
/// "https://www.example.com/", /// "https://www.example.com/",
/// )); /// ));
/// ``` /// ```
#[must_use]
pub fn new(inner: ExtXKey) -> Self { pub fn new(inner: ExtXKey) -> Self {
if inner.method() == EncryptionMethod::None { if inner.method() == EncryptionMethod::None {
panic!("the encryption method should never be `None`"); panic!("the encryption method should never be `None`");

View file

@ -201,6 +201,7 @@ impl VariantStream {
/// .unwrap(), /// .unwrap(),
/// )); /// ));
/// ``` /// ```
#[must_use]
pub fn is_associated(&self, media: &ExtXMedia) -> bool { pub fn is_associated(&self, media: &ExtXMedia) -> bool {
match &self { match &self {
Self::ExtXIFrame { stream_data, .. } => { Self::ExtXIFrame { stream_data, .. } => {

View file

@ -49,6 +49,7 @@ impl ExtXDiscontinuitySequence {
/// # use hls_m3u8::tags::ExtXDiscontinuitySequence; /// # use hls_m3u8::tags::ExtXDiscontinuitySequence;
/// let discontinuity_sequence = ExtXDiscontinuitySequence::new(5); /// let discontinuity_sequence = ExtXDiscontinuitySequence::new(5);
/// ``` /// ```
#[must_use]
pub const fn new(seq_num: u64) -> Self { Self { seq_num } } pub const fn new(seq_num: u64) -> Self { Self { seq_num } }
} }

View file

@ -27,6 +27,7 @@ impl ExtXMediaSequence {
/// # use hls_m3u8::tags::ExtXMediaSequence; /// # use hls_m3u8::tags::ExtXMediaSequence;
/// let media_sequence = ExtXMediaSequence::new(5); /// let media_sequence = ExtXMediaSequence::new(5);
/// ``` /// ```
#[must_use]
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, /// Returns the sequence number of the first media segment,
@ -40,6 +41,7 @@ impl ExtXMediaSequence {
/// ///
/// assert_eq!(media_sequence.seq_num(), 5); /// assert_eq!(media_sequence.seq_num(), 5);
/// ``` /// ```
#[must_use]
pub const fn seq_num(self) -> u64 { self.0 } pub const fn seq_num(self) -> u64 { self.0 }
/// Sets the sequence number. /// Sets the sequence number.

View file

@ -36,6 +36,7 @@ impl ExtXTargetDuration {
/// # Note /// # Note
/// ///
/// The nanoseconds part of the [`Duration`] will be discarded. /// 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())) } pub const fn new(duration: Duration) -> Self { Self(Duration::from_secs(duration.as_secs())) }
/// Returns the maximum media segment duration. /// Returns the maximum media segment duration.
@ -50,6 +51,7 @@ impl ExtXTargetDuration {
/// ///
/// assert_eq!(target_duration.duration(), Duration::from_secs(2)); /// assert_eq!(target_duration.duration(), Duration::from_secs(2));
/// ``` /// ```
#[must_use]
pub const fn duration(&self) -> Duration { self.0 } pub const fn duration(&self) -> Duration { self.0 }
} }

View file

@ -160,6 +160,7 @@ impl ExtXDateRange {
/// .and_hms_milli(14, 54, 23, 31), /// .and_hms_milli(14, 54, 23, 31),
/// ); /// );
/// ``` /// ```
#[must_use]
pub fn new<T: Into<String>>(id: T, start_date: DateTime<FixedOffset>) -> Self { pub fn new<T: Into<String>>(id: T, start_date: DateTime<FixedOffset>) -> Self {
Self { Self {
id: id.into(), id: id.into(),
@ -177,6 +178,7 @@ impl ExtXDateRange {
} }
/// Returns a builder for [`ExtXDateRange`]. /// Returns a builder for [`ExtXDateRange`].
#[must_use]
pub fn builder() -> ExtXDateRangeBuilder { ExtXDateRangeBuilder::default() } pub fn builder() -> ExtXDateRangeBuilder { ExtXDateRangeBuilder::default() }
} }

View file

@ -32,6 +32,7 @@ impl ExtInf {
/// ///
/// let ext_inf = ExtInf::new(Duration::from_secs(5)); /// let ext_inf = ExtInf::new(Duration::from_secs(5));
/// ``` /// ```
#[must_use]
pub const fn new(duration: Duration) -> Self { pub const fn new(duration: Duration) -> Self {
Self { Self {
duration, duration,
@ -49,6 +50,7 @@ impl ExtInf {
/// ///
/// let ext_inf = ExtInf::with_title(Duration::from_secs(5), "title"); /// let ext_inf = ExtInf::with_title(Duration::from_secs(5), "title");
/// ``` /// ```
#[must_use]
pub fn with_title<T: Into<String>>(duration: Duration, title: T) -> Self { pub fn with_title<T: Into<String>>(duration: Duration, title: T) -> Self {
Self { Self {
duration, duration,
@ -68,6 +70,7 @@ impl ExtInf {
/// ///
/// assert_eq!(ext_inf.duration(), Duration::from_secs(5)); /// assert_eq!(ext_inf.duration(), Duration::from_secs(5));
/// ``` /// ```
#[must_use]
pub const fn duration(&self) -> Duration { self.duration } pub const fn duration(&self) -> Duration { self.duration }
/// Sets the duration of the associated media segment. /// Sets the duration of the associated media segment.
@ -101,6 +104,7 @@ impl ExtInf {
/// ///
/// assert_eq!(ext_inf.title(), &Some("title".to_string())); /// assert_eq!(ext_inf.title(), &Some("title".to_string()));
/// ``` /// ```
#[must_use]
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. /// Sets the title of the associated media segment.

View file

@ -38,6 +38,7 @@ impl ExtXProgramDateTime {
/// .and_hms_milli(14, 54, 23, 31), /// .and_hms_milli(14, 54, 23, 31),
/// ); /// );
/// ``` /// ```
#[must_use]
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 /// 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) /// .and_hms_milli(14, 54, 23, 31)
/// ); /// );
/// ``` /// ```
#[must_use]
pub const fn date_time(&self) -> DateTime<FixedOffset> { self.0 } pub const fn date_time(&self) -> DateTime<FixedOffset> { self.0 }
/// Sets the date-time of the first sample of the associated media segment. /// Sets the date-time of the first sample of the associated media segment.

View file

@ -39,6 +39,7 @@ impl Float {
/// ``` /// ```
/// ///
/// [`NaN`]: core::f32::NAN /// [`NaN`]: core::f32::NAN
#[must_use]
pub fn new(float: f32) -> Self { pub fn new(float: f32) -> Self {
if float.is_infinite() { if float.is_infinite() {
panic!("float must be finite: `{}`", float); panic!("float must be finite: `{}`", float);
@ -59,6 +60,7 @@ impl Float {
/// # use hls_m3u8::types::Float; /// # use hls_m3u8::types::Float;
/// assert_eq!(Float::new(1.1_f32).as_f32(), 1.1_f32); /// assert_eq!(Float::new(1.1_f32).as_f32(), 1.1_f32);
/// ``` /// ```
#[must_use]
pub const fn as_f32(self) -> f32 { self.0 } pub const fn as_f32(self) -> f32 { self.0 }
} }

View file

@ -28,6 +28,8 @@ impl ProtocolVersion {
/// # use hls_m3u8::types::ProtocolVersion; /// # use hls_m3u8::types::ProtocolVersion;
/// assert_eq!(ProtocolVersion::latest(), ProtocolVersion::V7); /// assert_eq!(ProtocolVersion::latest(), ProtocolVersion::V7);
/// ``` /// ```
#[must_use]
#[inline]
pub const fn latest() -> Self { Self::V7 } pub const fn latest() -> Self { Self::V7 }
} }

View file

@ -223,6 +223,7 @@ impl StreamData {
/// # /// #
/// let stream = StreamData::new(20); /// let stream = StreamData::new(20);
/// ``` /// ```
#[must_use]
pub const fn new(bandwidth: u64) -> Self { pub const fn new(bandwidth: u64) -> Self {
Self { Self {
bandwidth, bandwidth,
@ -251,6 +252,7 @@ impl StreamData {
/// .build()?; /// .build()?;
/// # Ok::<(), Box<dyn ::std::error::Error>>(()) /// # Ok::<(), Box<dyn ::std::error::Error>>(())
/// ``` /// ```
#[must_use]
pub fn builder() -> StreamDataBuilder { StreamDataBuilder::default() } pub fn builder() -> StreamDataBuilder { StreamDataBuilder::default() }
} }

View file

@ -38,6 +38,7 @@ impl UFloat {
/// ``` /// ```
/// ///
/// [`NaN`]: core::f32::NAN /// [`NaN`]: core::f32::NAN
#[must_use]
pub fn new(float: f32) -> Self { pub fn new(float: f32) -> Self {
if float.is_infinite() { if float.is_infinite() {
panic!("float must be finite: `{}`", float); panic!("float must be finite: `{}`", float);
@ -62,6 +63,7 @@ impl UFloat {
/// # use hls_m3u8::types::UFloat; /// # use hls_m3u8::types::UFloat;
/// assert_eq!(UFloat::new(1.1_f32).as_f32(), 1.1_f32); /// assert_eq!(UFloat::new(1.1_f32).as_f32(), 1.1_f32);
/// ``` /// ```
#[must_use]
pub const fn as_f32(self) -> f32 { self.0 } pub const fn as_f32(self) -> f32 { self.0 }
} }