mirror of
https://github.com/sile/hls_m3u8.git
synced 2025-02-16 21:25:15 +00:00
fix some clippy lints
This commit is contained in:
parent
4ffd4350f8
commit
32876e1371
22 changed files with 117 additions and 126 deletions
|
@ -39,7 +39,7 @@ impl FromStr for AttributePairs {
|
||||||
type Err = Error;
|
type Err = Error;
|
||||||
|
|
||||||
fn from_str(input: &str) -> Result<Self, Self::Err> {
|
fn from_str(input: &str) -> Result<Self, Self::Err> {
|
||||||
let mut result = AttributePairs::new();
|
let mut result = Self::new();
|
||||||
|
|
||||||
for line in split(input, ',') {
|
for line in split(input, ',') {
|
||||||
let pair = split(line.trim(), '=');
|
let pair = split(line.trim(), '=');
|
||||||
|
@ -67,16 +67,12 @@ fn split(value: &str, terminator: char) -> Vec<String> {
|
||||||
let mut result = vec![];
|
let mut result = vec![];
|
||||||
|
|
||||||
let mut inside_quotes = false;
|
let mut inside_quotes = false;
|
||||||
let mut temp_string = String::new();
|
let mut temp_string = String::with_capacity(1024);
|
||||||
|
|
||||||
for c in value.chars() {
|
for c in value.chars() {
|
||||||
match c {
|
match c {
|
||||||
'"' => {
|
'"' => {
|
||||||
if inside_quotes {
|
inside_quotes = !inside_quotes;
|
||||||
inside_quotes = false;
|
|
||||||
} else {
|
|
||||||
inside_quotes = true;
|
|
||||||
}
|
|
||||||
temp_string.push(c);
|
temp_string.push(c);
|
||||||
}
|
}
|
||||||
k if (k == terminator) => {
|
k if (k == terminator) => {
|
||||||
|
@ -84,7 +80,7 @@ fn split(value: &str, terminator: char) -> Vec<String> {
|
||||||
temp_string.push(c);
|
temp_string.push(c);
|
||||||
} else {
|
} else {
|
||||||
result.push(temp_string);
|
result.push(temp_string);
|
||||||
temp_string = String::new();
|
temp_string = String::with_capacity(1024);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
|
|
18
src/error.rs
18
src/error.rs
|
@ -107,11 +107,11 @@ impl fmt::Display for Error {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<ErrorKind> for Error {
|
impl From<ErrorKind> for Error {
|
||||||
fn from(kind: ErrorKind) -> Error { Error::from(Context::new(kind)) }
|
fn from(kind: ErrorKind) -> Self { Self::from(Context::new(kind)) }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<Context<ErrorKind>> for Error {
|
impl From<Context<ErrorKind>> for Error {
|
||||||
fn from(inner: Context<ErrorKind>) -> Error { Error { inner } }
|
fn from(inner: Context<ErrorKind>) -> Self { Self { inner } }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Error {
|
impl Error {
|
||||||
|
@ -190,33 +190,33 @@ impl Error {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<::std::num::ParseIntError> for 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 { Self::parse_int_error(value) }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<::std::num::ParseFloatError> for Error {
|
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 { Self::parse_float_error(value) }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<::std::io::Error> for Error {
|
impl From<::std::io::Error> for Error {
|
||||||
fn from(value: ::std::io::Error) -> Self { Error::io(value) }
|
fn from(value: ::std::io::Error) -> Self { Self::io(value) }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<::chrono::ParseError> for Error {
|
impl From<::chrono::ParseError> for Error {
|
||||||
fn from(value: ::chrono::ParseError) -> Self { Error::chrono(value) }
|
fn from(value: ::chrono::ParseError) -> Self { Self::chrono(value) }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<::strum::ParseError> for Error {
|
impl From<::strum::ParseError> for Error {
|
||||||
fn from(value: ::strum::ParseError) -> Self {
|
fn from(value: ::strum::ParseError) -> Self {
|
||||||
Error::custom(value) // TODO!
|
Self::custom(value) // TODO!
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<String> for Error {
|
impl From<String> for Error {
|
||||||
fn from(value: String) -> Self { Error::custom(value) }
|
fn from(value: String) -> Self { Self::custom(value) }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<::core::convert::Infallible> for Error {
|
impl From<::core::convert::Infallible> for Error {
|
||||||
fn from(_: ::core::convert::Infallible) -> Self {
|
fn from(_: ::core::convert::Infallible) -> Self {
|
||||||
Error::custom("An Infallible error has been returned! (this should never happen!)")
|
Self::custom("An Infallible error has been returned! (this should never happen!)")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
94
src/line.rs
94
src/line.rs
|
@ -16,7 +16,7 @@ impl FromStr for Lines {
|
||||||
type Err = Error;
|
type Err = Error;
|
||||||
|
|
||||||
fn from_str(input: &str) -> Result<Self, Self::Err> {
|
fn from_str(input: &str) -> Result<Self, Self::Err> {
|
||||||
let mut result = Lines::new();
|
let mut result = Self::new();
|
||||||
|
|
||||||
let mut stream_inf = false;
|
let mut stream_inf = false;
|
||||||
let mut stream_inf_line = None;
|
let mut stream_inf_line = None;
|
||||||
|
@ -116,29 +116,29 @@ pub enum Tag {
|
||||||
impl fmt::Display for Tag {
|
impl fmt::Display for Tag {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
match &self {
|
match &self {
|
||||||
Tag::ExtM3u(value) => value.fmt(f),
|
Self::ExtM3u(value) => value.fmt(f),
|
||||||
Tag::ExtXVersion(value) => value.fmt(f),
|
Self::ExtXVersion(value) => value.fmt(f),
|
||||||
Tag::ExtInf(value) => value.fmt(f),
|
Self::ExtInf(value) => value.fmt(f),
|
||||||
Tag::ExtXByteRange(value) => value.fmt(f),
|
Self::ExtXByteRange(value) => value.fmt(f),
|
||||||
Tag::ExtXDiscontinuity(value) => value.fmt(f),
|
Self::ExtXDiscontinuity(value) => value.fmt(f),
|
||||||
Tag::ExtXKey(value) => value.fmt(f),
|
Self::ExtXKey(value) => value.fmt(f),
|
||||||
Tag::ExtXMap(value) => value.fmt(f),
|
Self::ExtXMap(value) => value.fmt(f),
|
||||||
Tag::ExtXProgramDateTime(value) => value.fmt(f),
|
Self::ExtXProgramDateTime(value) => value.fmt(f),
|
||||||
Tag::ExtXDateRange(value) => value.fmt(f),
|
Self::ExtXDateRange(value) => value.fmt(f),
|
||||||
Tag::ExtXTargetDuration(value) => value.fmt(f),
|
Self::ExtXTargetDuration(value) => value.fmt(f),
|
||||||
Tag::ExtXMediaSequence(value) => value.fmt(f),
|
Self::ExtXMediaSequence(value) => value.fmt(f),
|
||||||
Tag::ExtXDiscontinuitySequence(value) => value.fmt(f),
|
Self::ExtXDiscontinuitySequence(value) => value.fmt(f),
|
||||||
Tag::ExtXEndList(value) => value.fmt(f),
|
Self::ExtXEndList(value) => value.fmt(f),
|
||||||
Tag::ExtXPlaylistType(value) => value.fmt(f),
|
Self::ExtXPlaylistType(value) => value.fmt(f),
|
||||||
Tag::ExtXIFramesOnly(value) => value.fmt(f),
|
Self::ExtXIFramesOnly(value) => value.fmt(f),
|
||||||
Tag::ExtXMedia(value) => value.fmt(f),
|
Self::ExtXMedia(value) => value.fmt(f),
|
||||||
Tag::ExtXStreamInf(value) => value.fmt(f),
|
Self::ExtXStreamInf(value) => value.fmt(f),
|
||||||
Tag::ExtXIFrameStreamInf(value) => value.fmt(f),
|
Self::ExtXIFrameStreamInf(value) => value.fmt(f),
|
||||||
Tag::ExtXSessionData(value) => value.fmt(f),
|
Self::ExtXSessionData(value) => value.fmt(f),
|
||||||
Tag::ExtXSessionKey(value) => value.fmt(f),
|
Self::ExtXSessionKey(value) => value.fmt(f),
|
||||||
Tag::ExtXIndependentSegments(value) => value.fmt(f),
|
Self::ExtXIndependentSegments(value) => value.fmt(f),
|
||||||
Tag::ExtXStart(value) => value.fmt(f),
|
Self::ExtXStart(value) => value.fmt(f),
|
||||||
Tag::Unknown(value) => value.fmt(f),
|
Self::Unknown(value) => value.fmt(f),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -148,51 +148,51 @@ impl FromStr for Tag {
|
||||||
|
|
||||||
fn from_str(input: &str) -> Result<Self, Self::Err> {
|
fn from_str(input: &str) -> Result<Self, Self::Err> {
|
||||||
if input.starts_with(tags::ExtM3u::PREFIX) {
|
if input.starts_with(tags::ExtM3u::PREFIX) {
|
||||||
input.parse().map(Tag::ExtM3u)
|
input.parse().map(Self::ExtM3u)
|
||||||
} else if input.starts_with(tags::ExtXVersion::PREFIX) {
|
} else if input.starts_with(tags::ExtXVersion::PREFIX) {
|
||||||
input.parse().map(Tag::ExtXVersion)
|
input.parse().map(Self::ExtXVersion)
|
||||||
} else if input.starts_with(tags::ExtInf::PREFIX) {
|
} else if input.starts_with(tags::ExtInf::PREFIX) {
|
||||||
input.parse().map(Tag::ExtInf)
|
input.parse().map(Self::ExtInf)
|
||||||
} else if input.starts_with(tags::ExtXByteRange::PREFIX) {
|
} else if input.starts_with(tags::ExtXByteRange::PREFIX) {
|
||||||
input.parse().map(Tag::ExtXByteRange)
|
input.parse().map(Self::ExtXByteRange)
|
||||||
} else if input.starts_with(tags::ExtXDiscontinuity::PREFIX) {
|
} else if input.starts_with(tags::ExtXDiscontinuity::PREFIX) {
|
||||||
input.parse().map(Tag::ExtXDiscontinuity)
|
input.parse().map(Self::ExtXDiscontinuity)
|
||||||
} else if input.starts_with(tags::ExtXKey::PREFIX) {
|
} else if input.starts_with(tags::ExtXKey::PREFIX) {
|
||||||
input.parse().map(Tag::ExtXKey)
|
input.parse().map(Self::ExtXKey)
|
||||||
} else if input.starts_with(tags::ExtXMap::PREFIX) {
|
} else if input.starts_with(tags::ExtXMap::PREFIX) {
|
||||||
input.parse().map(Tag::ExtXMap)
|
input.parse().map(Self::ExtXMap)
|
||||||
} else if input.starts_with(tags::ExtXProgramDateTime::PREFIX) {
|
} else if input.starts_with(tags::ExtXProgramDateTime::PREFIX) {
|
||||||
input.parse().map(Tag::ExtXProgramDateTime)
|
input.parse().map(Self::ExtXProgramDateTime)
|
||||||
} else if input.starts_with(tags::ExtXTargetDuration::PREFIX) {
|
} else if input.starts_with(tags::ExtXTargetDuration::PREFIX) {
|
||||||
input.parse().map(Tag::ExtXTargetDuration)
|
input.parse().map(Self::ExtXTargetDuration)
|
||||||
} else if input.starts_with(tags::ExtXDateRange::PREFIX) {
|
} else if input.starts_with(tags::ExtXDateRange::PREFIX) {
|
||||||
input.parse().map(Tag::ExtXDateRange)
|
input.parse().map(Self::ExtXDateRange)
|
||||||
} else if input.starts_with(tags::ExtXMediaSequence::PREFIX) {
|
} else if input.starts_with(tags::ExtXMediaSequence::PREFIX) {
|
||||||
input.parse().map(Tag::ExtXMediaSequence)
|
input.parse().map(Self::ExtXMediaSequence)
|
||||||
} else if input.starts_with(tags::ExtXDiscontinuitySequence::PREFIX) {
|
} else if input.starts_with(tags::ExtXDiscontinuitySequence::PREFIX) {
|
||||||
input.parse().map(Tag::ExtXDiscontinuitySequence)
|
input.parse().map(Self::ExtXDiscontinuitySequence)
|
||||||
} else if input.starts_with(tags::ExtXEndList::PREFIX) {
|
} else if input.starts_with(tags::ExtXEndList::PREFIX) {
|
||||||
input.parse().map(Tag::ExtXEndList)
|
input.parse().map(Self::ExtXEndList)
|
||||||
} else if input.starts_with(tags::ExtXPlaylistType::PREFIX) {
|
} else if input.starts_with(tags::ExtXPlaylistType::PREFIX) {
|
||||||
input.parse().map(Tag::ExtXPlaylistType)
|
input.parse().map(Self::ExtXPlaylistType)
|
||||||
} else if input.starts_with(tags::ExtXIFramesOnly::PREFIX) {
|
} else if input.starts_with(tags::ExtXIFramesOnly::PREFIX) {
|
||||||
input.parse().map(Tag::ExtXIFramesOnly)
|
input.parse().map(Self::ExtXIFramesOnly)
|
||||||
} else if input.starts_with(tags::ExtXMedia::PREFIX) {
|
} else if input.starts_with(tags::ExtXMedia::PREFIX) {
|
||||||
input.parse().map(Tag::ExtXMedia).map_err(Error::custom)
|
input.parse().map(Self::ExtXMedia).map_err(Error::custom)
|
||||||
} else if input.starts_with(tags::ExtXStreamInf::PREFIX) {
|
} else if input.starts_with(tags::ExtXStreamInf::PREFIX) {
|
||||||
input.parse().map(Tag::ExtXStreamInf)
|
input.parse().map(Self::ExtXStreamInf)
|
||||||
} else if input.starts_with(tags::ExtXIFrameStreamInf::PREFIX) {
|
} else if input.starts_with(tags::ExtXIFrameStreamInf::PREFIX) {
|
||||||
input.parse().map(Tag::ExtXIFrameStreamInf)
|
input.parse().map(Self::ExtXIFrameStreamInf)
|
||||||
} else if input.starts_with(tags::ExtXSessionData::PREFIX) {
|
} else if input.starts_with(tags::ExtXSessionData::PREFIX) {
|
||||||
input.parse().map(Tag::ExtXSessionData)
|
input.parse().map(Self::ExtXSessionData)
|
||||||
} else if input.starts_with(tags::ExtXSessionKey::PREFIX) {
|
} else if input.starts_with(tags::ExtXSessionKey::PREFIX) {
|
||||||
input.parse().map(Tag::ExtXSessionKey)
|
input.parse().map(Self::ExtXSessionKey)
|
||||||
} else if input.starts_with(tags::ExtXIndependentSegments::PREFIX) {
|
} else if input.starts_with(tags::ExtXIndependentSegments::PREFIX) {
|
||||||
input.parse().map(Tag::ExtXIndependentSegments)
|
input.parse().map(Self::ExtXIndependentSegments)
|
||||||
} else if input.starts_with(tags::ExtXStart::PREFIX) {
|
} else if input.starts_with(tags::ExtXStart::PREFIX) {
|
||||||
input.parse().map(Tag::ExtXStart)
|
input.parse().map(Self::ExtXStart)
|
||||||
} else {
|
} else {
|
||||||
Ok(Tag::Unknown(input.to_string()))
|
Ok(Self::Unknown(input.to_string()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -90,7 +90,7 @@ impl MasterPlaylist {
|
||||||
where
|
where
|
||||||
T: Into<ExtXIndependentSegments>,
|
T: Into<ExtXIndependentSegments>,
|
||||||
{
|
{
|
||||||
self.independent_segments_tag = value.map(|v| v.into());
|
self.independent_segments_tag = value.map(Into::into);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -102,7 +102,7 @@ impl MasterPlaylist {
|
||||||
where
|
where
|
||||||
T: Into<ExtXStart>,
|
T: Into<ExtXStart>,
|
||||||
{
|
{
|
||||||
self.start_tag = value.map(|v| v.into());
|
self.start_tag = value.map(Into::into);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -120,7 +120,7 @@ impl MasterPlaylist {
|
||||||
where
|
where
|
||||||
T: Into<ExtXMedia>,
|
T: Into<ExtXMedia>,
|
||||||
{
|
{
|
||||||
self.media_tags = value.into_iter().map(|v| v.into()).collect();
|
self.media_tags = value.into_iter().map(Into::into).collect();
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -138,7 +138,7 @@ impl MasterPlaylist {
|
||||||
where
|
where
|
||||||
T: Into<ExtXStreamInf>,
|
T: Into<ExtXStreamInf>,
|
||||||
{
|
{
|
||||||
self.stream_inf_tags = value.into_iter().map(|v| v.into()).collect();
|
self.stream_inf_tags = value.into_iter().map(Into::into).collect();
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -158,7 +158,7 @@ impl MasterPlaylist {
|
||||||
where
|
where
|
||||||
T: Into<ExtXIFrameStreamInf>,
|
T: Into<ExtXIFrameStreamInf>,
|
||||||
{
|
{
|
||||||
self.i_frame_stream_inf_tags = value.into_iter().map(|v| v.into()).collect();
|
self.i_frame_stream_inf_tags = value.into_iter().map(Into::into).collect();
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -176,7 +176,7 @@ impl MasterPlaylist {
|
||||||
where
|
where
|
||||||
T: Into<ExtXSessionData>,
|
T: Into<ExtXSessionData>,
|
||||||
{
|
{
|
||||||
self.session_data_tags = value.into_iter().map(|v| v.into()).collect();
|
self.session_data_tags = value.into_iter().map(Into::into).collect();
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -194,7 +194,7 @@ impl MasterPlaylist {
|
||||||
where
|
where
|
||||||
T: Into<ExtXSessionKey>,
|
T: Into<ExtXSessionKey>,
|
||||||
{
|
{
|
||||||
self.session_key_tags = value.into_iter().map(|v| v.into()).collect();
|
self.session_key_tags = value.into_iter().map(Into::into).collect();
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -367,7 +367,7 @@ impl FromStr for MasterPlaylist {
|
||||||
type Err = Error;
|
type Err = Error;
|
||||||
|
|
||||||
fn from_str(input: &str) -> Result<Self, Self::Err> {
|
fn from_str(input: &str) -> Result<Self, Self::Err> {
|
||||||
let mut builder = MasterPlaylist::builder();
|
let mut builder = Self::builder();
|
||||||
|
|
||||||
let mut media_tags = vec![];
|
let mut media_tags = vec![];
|
||||||
let mut stream_inf_tags = vec![];
|
let mut stream_inf_tags = vec![];
|
||||||
|
|
|
@ -42,15 +42,6 @@ impl ExtM3u {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// This tag requires [`ProtocolVersion::V1`].
|
/// This tag requires [`ProtocolVersion::V1`].
|
||||||
///
|
|
||||||
/// # Example
|
|
||||||
/// ```
|
|
||||||
/// # use hls_m3u8::tags::ExtM3u;
|
|
||||||
/// use hls_m3u8::types::ProtocolVersion;
|
|
||||||
/// use hls_m3u8::RequiredVersion;
|
|
||||||
///
|
|
||||||
/// assert_eq!(ExtM3u.required_version(), ProtocolVersion::V1);
|
|
||||||
/// ```
|
|
||||||
impl RequiredVersion for ExtM3u {
|
impl RequiredVersion for ExtM3u {
|
||||||
fn required_version(&self) -> ProtocolVersion { ProtocolVersion::V1 }
|
fn required_version(&self) -> ProtocolVersion { ProtocolVersion::V1 }
|
||||||
}
|
}
|
||||||
|
@ -81,4 +72,9 @@ mod test {
|
||||||
fn test_parser() {
|
fn test_parser() {
|
||||||
assert_eq!("#EXTM3U".parse::<ExtM3u>().unwrap(), ExtM3u);
|
assert_eq!("#EXTM3U".parse::<ExtM3u>().unwrap(), ExtM3u);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_required_version() {
|
||||||
|
assert_eq!(ExtM3u.required_version(), ProtocolVersion::V1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -101,7 +101,7 @@ impl ExtXIFrameStreamInf {
|
||||||
/// let stream = ExtXIFrameStreamInf::new("https://www.example.com", 20);
|
/// let stream = ExtXIFrameStreamInf::new("https://www.example.com", 20);
|
||||||
/// ```
|
/// ```
|
||||||
pub fn new<T: ToString>(uri: T, bandwidth: u64) -> Self {
|
pub fn new<T: ToString>(uri: T, bandwidth: u64) -> Self {
|
||||||
ExtXIFrameStreamInf {
|
Self {
|
||||||
uri: uri.to_string(),
|
uri: uri.to_string(),
|
||||||
stream_inf: StreamInf::new(bandwidth),
|
stream_inf: StreamInf::new(bandwidth),
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,6 +9,7 @@ use crate::utils::{parse_yes_or_no, quote, tag, unquote};
|
||||||
use crate::{Error, RequiredVersion};
|
use crate::{Error, RequiredVersion};
|
||||||
|
|
||||||
/// # [4.4.5.1. EXT-X-MEDIA]
|
/// # [4.4.5.1. EXT-X-MEDIA]
|
||||||
|
///
|
||||||
/// The [`ExtXMedia`] tag is used to relate [`Media Playlist`]s,
|
/// The [`ExtXMedia`] tag is used to relate [`Media Playlist`]s,
|
||||||
/// that contain alternative Renditions of the same content.
|
/// that contain alternative Renditions of the same content.
|
||||||
///
|
///
|
||||||
|
@ -308,7 +309,7 @@ impl ExtXMedia {
|
||||||
///
|
///
|
||||||
/// [`Media Playlist`]: crate::MediaPlaylist
|
/// [`Media Playlist`]: crate::MediaPlaylist
|
||||||
pub fn set_uri<T: Into<String>>(&mut self, value: Option<T>) -> &mut Self {
|
pub fn set_uri<T: Into<String>>(&mut self, value: Option<T>) -> &mut Self {
|
||||||
self.uri = value.map(|v| v.into());
|
self.uri = value.map(Into::into);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -346,7 +347,7 @@ impl ExtXMedia {
|
||||||
///
|
///
|
||||||
/// [`RFC5646`]: https://tools.ietf.org/html/rfc5646
|
/// [`RFC5646`]: https://tools.ietf.org/html/rfc5646
|
||||||
pub fn set_language<T: Into<String>>(&mut self, value: Option<T>) -> &mut Self {
|
pub fn set_language<T: Into<String>>(&mut self, value: Option<T>) -> &mut Self {
|
||||||
self.language = value.map(|v| v.into());
|
self.language = value.map(Into::into);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -386,7 +387,7 @@ impl ExtXMedia {
|
||||||
///
|
///
|
||||||
/// [`language`]: #method.language
|
/// [`language`]: #method.language
|
||||||
pub fn set_assoc_language<T: Into<String>>(&mut self, value: Option<T>) -> &mut Self {
|
pub fn set_assoc_language<T: Into<String>>(&mut self, value: Option<T>) -> &mut Self {
|
||||||
self.assoc_language = value.map(|v| v.into());
|
self.assoc_language = value.map(Into::into);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -588,7 +589,7 @@ impl ExtXMedia {
|
||||||
/// [`UTI`]: https://tools.ietf.org/html/draft-pantos-hls-rfc8216bis-05#ref-UTI
|
/// [`UTI`]: https://tools.ietf.org/html/draft-pantos-hls-rfc8216bis-05#ref-UTI
|
||||||
/// [`subtitles`]: crate::types::MediaType::Subtitles
|
/// [`subtitles`]: crate::types::MediaType::Subtitles
|
||||||
pub fn set_characteristics<T: Into<String>>(&mut self, value: Option<T>) -> &mut Self {
|
pub fn set_characteristics<T: Into<String>>(&mut self, value: Option<T>) -> &mut Self {
|
||||||
self.characteristics = value.map(|v| v.into());
|
self.characteristics = value.map(Into::into);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -623,7 +624,7 @@ impl ExtXMedia {
|
||||||
/// assert_eq!(media.channels(), &Some(Channels::new(6)));
|
/// assert_eq!(media.channels(), &Some(Channels::new(6)));
|
||||||
/// ```
|
/// ```
|
||||||
pub fn set_channels<T: Into<Channels>>(&mut self, value: Option<T>) -> &mut Self {
|
pub fn set_channels<T: Into<Channels>>(&mut self, value: Option<T>) -> &mut Self {
|
||||||
self.channels = value.map(|v| v.into());
|
self.channels = value.map(Into::into);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,14 +8,17 @@ use crate::types::ProtocolVersion;
|
||||||
use crate::utils::{quote, tag, unquote};
|
use crate::utils::{quote, tag, unquote};
|
||||||
use crate::{Error, RequiredVersion};
|
use crate::{Error, RequiredVersion};
|
||||||
|
|
||||||
/// The data of an [ExtXSessionData] tag.
|
/// The data of an [`ExtXSessionData`] tag.
|
||||||
#[derive(Hash, Eq, Ord, Debug, PartialEq, Clone, PartialOrd)]
|
#[derive(Hash, Eq, Ord, Debug, PartialEq, Clone, PartialOrd)]
|
||||||
pub enum SessionData {
|
pub enum SessionData {
|
||||||
/// A String, that contains the data identified by
|
/// A String, that contains the data identified by
|
||||||
/// [`data_id`](ExtXSessionData::data_id).
|
/// [`data_id`].
|
||||||
/// If a [`language`](ExtXSessionData::language) is specified, the value
|
/// If a [`language`] is specified, the value
|
||||||
/// should contain a human-readable string written in the specified
|
/// should contain a human-readable string written in the specified
|
||||||
/// language.
|
/// language.
|
||||||
|
///
|
||||||
|
/// [`data_id`]: ExtXSessionData::data_id
|
||||||
|
/// [`language`]: ExtXSessionData::language
|
||||||
Value(String),
|
Value(String),
|
||||||
/// An [`uri`], which points to a [`json`].
|
/// An [`uri`], which points to a [`json`].
|
||||||
///
|
///
|
||||||
|
@ -35,17 +38,20 @@ pub enum SessionData {
|
||||||
#[builder(setter(into))]
|
#[builder(setter(into))]
|
||||||
pub struct ExtXSessionData {
|
pub struct ExtXSessionData {
|
||||||
/// The identifier of the data.
|
/// The identifier of the data.
|
||||||
/// For more information look [`here`](ExtXSessionData::set_data_id).
|
/// For more information look [`here`].
|
||||||
///
|
///
|
||||||
/// # Note
|
/// # Note
|
||||||
/// This field is required.
|
/// This field is required.
|
||||||
|
///
|
||||||
|
/// [`here`]: ExtXSessionData::set_data_id
|
||||||
data_id: String,
|
data_id: String,
|
||||||
/// The data associated with the
|
/// The data associated with the [`data_id`].
|
||||||
/// [`data_id`](ExtXSessionDataBuilder::data_id).
|
|
||||||
/// For more information look [`here`](SessionData).
|
/// For more information look [`here`](SessionData).
|
||||||
///
|
///
|
||||||
/// # Note
|
/// # Note
|
||||||
/// This field is required.
|
/// This field is required.
|
||||||
|
///
|
||||||
|
/// [`data_id`]: ExtXSessionDataBuilder::data_id
|
||||||
data: SessionData,
|
data: SessionData,
|
||||||
/// The language of the [`data`](ExtXSessionDataBuilder::data).
|
/// The language of the [`data`](ExtXSessionDataBuilder::data).
|
||||||
#[builder(setter(into, strip_option), default)]
|
#[builder(setter(into, strip_option), default)]
|
||||||
|
|
|
@ -191,7 +191,7 @@ impl ExtXStreamInf {
|
||||||
/// assert_eq!(stream.frame_rate(), Some(59.9));
|
/// assert_eq!(stream.frame_rate(), Some(59.9));
|
||||||
/// ```
|
/// ```
|
||||||
pub fn set_frame_rate(&mut self, value: Option<f64>) -> &mut Self {
|
pub fn set_frame_rate(&mut self, value: Option<f64>) -> &mut Self {
|
||||||
self.frame_rate = value.map(|v| v.into());
|
self.frame_rate = value.map(Into::into);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -233,7 +233,7 @@ impl ExtXStreamInf {
|
||||||
/// assert_eq!(stream.audio(), &Some("audio".to_string()));
|
/// assert_eq!(stream.audio(), &Some("audio".to_string()));
|
||||||
/// ```
|
/// ```
|
||||||
pub fn set_audio<T: Into<String>>(&mut self, value: Option<T>) -> &mut Self {
|
pub fn set_audio<T: Into<String>>(&mut self, value: Option<T>) -> &mut Self {
|
||||||
self.audio = value.map(|v| v.into());
|
self.audio = value.map(Into::into);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -262,7 +262,7 @@ impl ExtXStreamInf {
|
||||||
/// assert_eq!(stream.subtitles(), &Some("subs".to_string()));
|
/// assert_eq!(stream.subtitles(), &Some("subs".to_string()));
|
||||||
/// ```
|
/// ```
|
||||||
pub fn set_subtitles<T: Into<String>>(&mut self, value: Option<T>) -> &mut Self {
|
pub fn set_subtitles<T: Into<String>>(&mut self, value: Option<T>) -> &mut Self {
|
||||||
self.subtitles = value.map(|v| v.into());
|
self.subtitles = value.map(Into::into);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -38,7 +38,7 @@ impl FromStr for ExtXEndList {
|
||||||
|
|
||||||
fn from_str(input: &str) -> Result<Self, Self::Err> {
|
fn from_str(input: &str) -> Result<Self, Self::Err> {
|
||||||
tag(input, Self::PREFIX)?;
|
tag(input, Self::PREFIX)?;
|
||||||
Ok(ExtXEndList)
|
Ok(Self)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -40,7 +40,7 @@ impl FromStr for ExtXIFramesOnly {
|
||||||
|
|
||||||
fn from_str(input: &str) -> Result<Self, Self::Err> {
|
fn from_str(input: &str) -> Result<Self, Self::Err> {
|
||||||
tag(input, Self::PREFIX)?;
|
tag(input, Self::PREFIX)?;
|
||||||
Ok(ExtXIFramesOnly)
|
Ok(Self)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -74,7 +74,7 @@ impl FromStr for ExtXMediaSequence {
|
||||||
|
|
||||||
fn from_str(input: &str) -> Result<Self, Self::Err> {
|
fn from_str(input: &str) -> Result<Self, Self::Err> {
|
||||||
let seq_num = tag(input, Self::PREFIX)?.parse()?;
|
let seq_num = tag(input, Self::PREFIX)?.parse()?;
|
||||||
Ok(ExtXMediaSequence::new(seq_num))
|
Ok(Self::new(seq_num))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -97,7 +97,7 @@ impl FromStr for ExtXByteRange {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(ExtXByteRange::new(length, start))
|
Ok(Self::new(length, start))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -37,7 +37,7 @@ impl FromStr for ExtXDiscontinuity {
|
||||||
|
|
||||||
fn from_str(input: &str) -> Result<Self, Self::Err> {
|
fn from_str(input: &str) -> Result<Self, Self::Err> {
|
||||||
tag(input, Self::PREFIX)?;
|
tag(input, Self::PREFIX)?;
|
||||||
Ok(ExtXDiscontinuity)
|
Ok(Self)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -130,10 +130,7 @@ impl RequiredVersion for ExtInf {
|
||||||
impl fmt::Display for ExtInf {
|
impl fmt::Display for ExtInf {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
write!(f, "{}", Self::PREFIX)?;
|
write!(f, "{}", Self::PREFIX)?;
|
||||||
|
write!(f, "{},", self.duration.as_secs_f64())?;
|
||||||
let duration = (self.duration.as_secs() as f64)
|
|
||||||
+ (f64::from(self.duration.subsec_nanos()) / 1_000_000_000.0);
|
|
||||||
write!(f, "{},", duration)?;
|
|
||||||
|
|
||||||
if let Some(value) = &self.title {
|
if let Some(value) = &self.title {
|
||||||
write!(f, "{}", value)?;
|
write!(f, "{}", value)?;
|
||||||
|
|
|
@ -11,11 +11,6 @@ use crate::{Encrypted, Error, RequiredVersion};
|
||||||
/// The [`ExtXMap`] tag specifies how to obtain the Media Initialization
|
/// The [`ExtXMap`] tag specifies how to obtain the Media Initialization
|
||||||
/// Section, required to parse the applicable [Media Segment]s.
|
/// Section, required to parse the applicable [Media Segment]s.
|
||||||
///
|
///
|
||||||
/// Its format is:
|
|
||||||
/// ```text
|
|
||||||
/// #EXT-X-MAP:<attribute-list>
|
|
||||||
/// ```
|
|
||||||
///
|
|
||||||
/// [Media Segment]: crate::MediaSegment
|
/// [Media Segment]: crate::MediaSegment
|
||||||
/// [4.4.2.5. EXT-X-MAP]:
|
/// [4.4.2.5. EXT-X-MAP]:
|
||||||
/// https://tools.ietf.org/html/draft-pantos-hls-rfc8216bis-04#section-4.4.2.5
|
/// https://tools.ietf.org/html/draft-pantos-hls-rfc8216bis-04#section-4.4.2.5
|
||||||
|
|
|
@ -28,7 +28,7 @@ impl FromStr for ExtXIndependentSegments {
|
||||||
|
|
||||||
fn from_str(input: &str) -> Result<Self, Self::Err> {
|
fn from_str(input: &str) -> Result<Self, Self::Err> {
|
||||||
tag(input, Self::PREFIX)?;
|
tag(input, Self::PREFIX)?;
|
||||||
Ok(ExtXIndependentSegments)
|
Ok(Self)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -63,7 +63,7 @@ impl From<f64> for DecimalFloatingPoint {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<f32> for DecimalFloatingPoint {
|
impl From<f32> for DecimalFloatingPoint {
|
||||||
fn from(value: f32) -> Self { (value as f64).into() }
|
fn from(value: f32) -> Self { f64::from(value).into() }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
@ -86,7 +86,7 @@ mod tests {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
test_from![1u8, 1u16, 1u32, 1.0f32, -1.0f32, 1.0f64, -1.0f64];
|
test_from![1_u8, 1_u16, 1_u32, 1.0_f32, -1.0_f32, 1.0_f64, -1.0_f64];
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
pub fn test_display() {
|
pub fn test_display() {
|
||||||
|
|
|
@ -42,7 +42,7 @@ impl DecimalResolution {
|
||||||
|
|
||||||
/// [`DecimalResolution`] can be constructed from a tuple; `(width, height)`.
|
/// [`DecimalResolution`] can be constructed from a tuple; `(width, height)`.
|
||||||
impl From<(usize, usize)> for DecimalResolution {
|
impl From<(usize, usize)> for DecimalResolution {
|
||||||
fn from(value: (usize, usize)) -> Self { DecimalResolution::new(value.0, value.1) }
|
fn from(value: (usize, usize)) -> Self { Self::new(value.0, value.1) }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FromStr for DecimalResolution {
|
impl FromStr for DecimalResolution {
|
||||||
|
|
|
@ -221,7 +221,7 @@ impl DecryptionKey {
|
||||||
/// 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 {
|
pub fn set_key_format<T: Into<KeyFormat>>(&mut self, value: Option<T>) -> &mut Self {
|
||||||
self.key_format = value.map(|v| v.into());
|
self.key_format = value.map(Into::into);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -266,7 +266,7 @@ impl DecryptionKey {
|
||||||
&mut self,
|
&mut self,
|
||||||
value: Option<T>,
|
value: Option<T>,
|
||||||
) -> &mut Self {
|
) -> &mut Self {
|
||||||
self.key_format_versions = value.map(|v| v.into());
|
self.key_format_versions = value.map(Into::into);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -54,21 +54,21 @@ mod tests {
|
||||||
}
|
}
|
||||||
|
|
||||||
test_from![
|
test_from![
|
||||||
SignedDecimalFloatingPoint::from(1u8) => SignedDecimalFloatingPoint::new(1.0),
|
SignedDecimalFloatingPoint::from(1_u8) => SignedDecimalFloatingPoint::new(1.0),
|
||||||
SignedDecimalFloatingPoint::from(1i8) => SignedDecimalFloatingPoint::new(1.0),
|
SignedDecimalFloatingPoint::from(1_i8) => SignedDecimalFloatingPoint::new(1.0),
|
||||||
SignedDecimalFloatingPoint::from(1u16) => SignedDecimalFloatingPoint::new(1.0),
|
SignedDecimalFloatingPoint::from(1_u16) => SignedDecimalFloatingPoint::new(1.0),
|
||||||
SignedDecimalFloatingPoint::from(1i16) => SignedDecimalFloatingPoint::new(1.0),
|
SignedDecimalFloatingPoint::from(1_i16) => SignedDecimalFloatingPoint::new(1.0),
|
||||||
SignedDecimalFloatingPoint::from(1u32) => SignedDecimalFloatingPoint::new(1.0),
|
SignedDecimalFloatingPoint::from(1_u32) => SignedDecimalFloatingPoint::new(1.0),
|
||||||
SignedDecimalFloatingPoint::from(1i32) => SignedDecimalFloatingPoint::new(1.0),
|
SignedDecimalFloatingPoint::from(1_i32) => SignedDecimalFloatingPoint::new(1.0),
|
||||||
SignedDecimalFloatingPoint::from(1.0f32) => SignedDecimalFloatingPoint::new(1.0),
|
SignedDecimalFloatingPoint::from(1.0_f32) => SignedDecimalFloatingPoint::new(1.0),
|
||||||
SignedDecimalFloatingPoint::from(1.0f64) => SignedDecimalFloatingPoint::new(1.0)
|
SignedDecimalFloatingPoint::from(1.0_f64) => SignedDecimalFloatingPoint::new(1.0)
|
||||||
];
|
];
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_display() {
|
fn test_display() {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
SignedDecimalFloatingPoint::new(1.0).to_string(),
|
SignedDecimalFloatingPoint::new(1.0).to_string(),
|
||||||
1.0f64.to_string()
|
1.0_f64.to_string()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -229,7 +229,7 @@ impl StreamInf {
|
||||||
/// assert_eq!(stream.hdcp_level(), Some(HdcpLevel::None));
|
/// assert_eq!(stream.hdcp_level(), Some(HdcpLevel::None));
|
||||||
/// ```
|
/// ```
|
||||||
pub fn set_hdcp_level<T: Into<HdcpLevel>>(&mut self, value: Option<T>) -> &mut Self {
|
pub fn set_hdcp_level<T: Into<HdcpLevel>>(&mut self, value: Option<T>) -> &mut Self {
|
||||||
self.hdcp_level = value.map(|v| v.into());
|
self.hdcp_level = value.map(Into::into);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue