1
0
Fork 0
mirror of https://github.com/sile/hls_m3u8.git synced 2024-05-18 16:28:20 +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(
clippy::multiple_crate_versions,
clippy::must_use_candidate,
clippy::module_name_repetitions,
clippy::default_trait_access
)]

View file

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

View file

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

View file

@ -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 }
}

View file

@ -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<T, K>(media_type: MediaType, group_id: T, name: K) -> Self
where
T: Into<String>,
@ -213,6 +214,7 @@ impl ExtXMedia {
}
/// Returns a builder for [`ExtXMedia`].
#[must_use]
pub fn builder() -> ExtXMediaBuilder { ExtXMediaBuilder::default() }
}

View file

@ -140,6 +140,7 @@ impl ExtXSessionData {
/// SessionData::Uri("https://www.example.com/".to_string()),
/// );
/// ```
#[must_use]
pub fn new<T: Into<String>>(data_id: T, data: SessionData) -> Self {
Self {
data_id: data_id.into(),
@ -163,6 +164,7 @@ impl ExtXSessionData {
/// .build()?;
/// # Ok::<(), Box<dyn ::std::error::Error>>(())
/// ```
#[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<T, K>(data_id: T, data: SessionData, language: K) -> Self
where
T: Into<String>,

View file

@ -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`");

View file

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

View file

@ -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 } }
}

View file

@ -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.

View file

@ -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 }
}

View file

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

View file

@ -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<T: Into<String>>(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<String> { &self.title }
/// Sets the title of the associated media segment.

View file

@ -38,6 +38,7 @@ impl ExtXProgramDateTime {
/// .and_hms_milli(14, 54, 23, 31),
/// );
/// ```
#[must_use]
pub const fn new(date_time: DateTime<FixedOffset>) -> 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<FixedOffset> { self.0 }
/// 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
#[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 }
}

View file

@ -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 }
}

View file

@ -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<dyn ::std::error::Error>>(())
/// ```
#[must_use]
pub fn builder() -> StreamDataBuilder { StreamDataBuilder::default() }
}

View file

@ -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 }
}