mirror of
https://github.com/sile/hls_m3u8.git
synced 2025-01-08 19:25:24 +00:00
some minor fixes
This commit is contained in:
parent
7a63c2dcf2
commit
cc48478b05
2 changed files with 32 additions and 22 deletions
|
@ -107,6 +107,13 @@ impl Error {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub(crate) fn missing_field<T: fmt::Display, D: fmt::Display>(strct: D, field: T) -> Self {
|
||||||
|
Self::new(ErrorKind::Custom(format!(
|
||||||
|
"the field `{}` is missing for `{}`",
|
||||||
|
field, strct
|
||||||
|
)))
|
||||||
|
}
|
||||||
|
|
||||||
pub(crate) fn unexpected_attribute<T: ToString>(value: T) -> Self {
|
pub(crate) fn unexpected_attribute<T: ToString>(value: T) -> Self {
|
||||||
Self::new(ErrorKind::UnexpectedAttribute {
|
Self::new(ErrorKind::UnexpectedAttribute {
|
||||||
attribute: value.to_string(),
|
attribute: value.to_string(),
|
||||||
|
|
|
@ -39,40 +39,23 @@ pub trait Decryptable: private::Sealed {
|
||||||
/// Most of the time only a single key is provided, so instead of iterating
|
/// Most of the time only a single key is provided, so instead of iterating
|
||||||
/// through all keys, one might as well just get the first key.
|
/// through all keys, one might as well just get the first key.
|
||||||
#[must_use]
|
#[must_use]
|
||||||
|
#[inline]
|
||||||
fn first_key(&self) -> Option<&DecryptionKey> {
|
fn first_key(&self) -> Option<&DecryptionKey> {
|
||||||
<Self as Decryptable>::keys(self).first().copied()
|
<Self as Decryptable>::keys(self).first().copied()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the number of keys.
|
/// Returns the number of keys.
|
||||||
#[must_use]
|
#[must_use]
|
||||||
|
#[inline]
|
||||||
fn len(&self) -> usize { <Self as Decryptable>::keys(self).len() }
|
fn len(&self) -> usize { <Self as Decryptable>::keys(self).len() }
|
||||||
|
|
||||||
|
/// Returns `true`, if the number of keys is zero.
|
||||||
#[must_use]
|
#[must_use]
|
||||||
|
#[inline]
|
||||||
fn is_empty(&self) -> bool { <Self as Decryptable>::len(self) == 0 }
|
fn is_empty(&self) -> bool { <Self as Decryptable>::len(self) == 0 }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # Example
|
#[doc(hidden)]
|
||||||
///
|
|
||||||
/// Implementing it:
|
|
||||||
///
|
|
||||||
/// ```
|
|
||||||
/// # use hls_m3u8::RequiredVersion;
|
|
||||||
/// use hls_m3u8::types::ProtocolVersion;
|
|
||||||
///
|
|
||||||
/// struct ExampleTag(u64);
|
|
||||||
///
|
|
||||||
/// impl RequiredVersion for ExampleTag {
|
|
||||||
/// fn required_version(&self) -> ProtocolVersion {
|
|
||||||
/// if self.0 == 5 {
|
|
||||||
/// ProtocolVersion::V4
|
|
||||||
/// } else {
|
|
||||||
/// ProtocolVersion::V1
|
|
||||||
/// }
|
|
||||||
/// }
|
|
||||||
/// }
|
|
||||||
/// assert_eq!(ExampleTag(5).required_version(), ProtocolVersion::V4);
|
|
||||||
/// assert_eq!(ExampleTag(2).required_version(), ProtocolVersion::V1);
|
|
||||||
/// ```
|
|
||||||
pub trait RequiredVersion {
|
pub trait RequiredVersion {
|
||||||
/// Returns the protocol compatibility version that this tag requires.
|
/// Returns the protocol compatibility version that this tag requires.
|
||||||
///
|
///
|
||||||
|
@ -80,9 +63,11 @@ pub trait RequiredVersion {
|
||||||
///
|
///
|
||||||
/// This is for the latest working [`ProtocolVersion`] and a client, that
|
/// This is for the latest working [`ProtocolVersion`] and a client, that
|
||||||
/// only supports an older version would break.
|
/// only supports an older version would break.
|
||||||
|
#[must_use]
|
||||||
fn required_version(&self) -> ProtocolVersion;
|
fn required_version(&self) -> ProtocolVersion;
|
||||||
|
|
||||||
/// The protocol version, in which the tag has been introduced.
|
/// The protocol version, in which the tag has been introduced.
|
||||||
|
#[must_use]
|
||||||
fn introduced_version(&self) -> ProtocolVersion { self.required_version() }
|
fn introduced_version(&self) -> ProtocolVersion { self.required_version() }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -96,6 +81,15 @@ impl<T: RequiredVersion> RequiredVersion for Vec<T> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<K, V: RequiredVersion> RequiredVersion for BTreeMap<K, V> {
|
||||||
|
fn required_version(&self) -> ProtocolVersion {
|
||||||
|
self.values()
|
||||||
|
.map(RequiredVersion::required_version)
|
||||||
|
.max()
|
||||||
|
.unwrap_or_default()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<T: RequiredVersion> RequiredVersion for Option<T> {
|
impl<T: RequiredVersion> RequiredVersion for Option<T> {
|
||||||
fn required_version(&self) -> ProtocolVersion {
|
fn required_version(&self) -> ProtocolVersion {
|
||||||
self.iter()
|
self.iter()
|
||||||
|
@ -105,6 +99,15 @@ impl<T: RequiredVersion> RequiredVersion for Option<T> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<K, V: RequiredVersion, S> RequiredVersion for HashMap<K, V, S> {
|
||||||
|
fn required_version(&self) -> ProtocolVersion {
|
||||||
|
self.values()
|
||||||
|
.map(RequiredVersion::required_version)
|
||||||
|
.max()
|
||||||
|
.unwrap_or_default()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
Loading…
Reference in a new issue