Apply clippy suggestions

This commit is contained in:
Rafael Caricio 2021-10-18 11:48:30 +02:00
parent 39aab3a2ac
commit 3d5599fa28
Signed by: rafaelcaricio
GPG key ID: 3C86DBCE8E93C947
2 changed files with 28 additions and 30 deletions

View file

@ -598,7 +598,7 @@ named!(pub duration_title_tag<(f32, Option<String>)>,
named!(pub key<Key>, map!(key_value_pairs, Key::from_hashmap)); named!(pub key<Key>, map!(key_value_pairs, Key::from_hashmap));
named!(pub extmap<Map>, map!(key_value_pairs, |attrs| Map { named!(pub extmap<Map>, map!(key_value_pairs, |attrs| Map {
uri: attrs.get("URI").map(|u| u.clone()).unwrap_or_default(), uri: attrs.get("URI").cloned().unwrap_or_default(),
byte_range: attrs.get("BYTERANGE").map(|range| { byte_range: attrs.get("BYTERANGE").map(|range| {
match byte_range_val(range.as_bytes()) { match byte_range_val(range.as_bytes()) {
IResult::Ok((_, br)) => br, IResult::Ok((_, br)) => br,
@ -636,7 +636,7 @@ named!(pub ext_tag<ExtTag>,
>> rest: opt!(map_res!(is_not!("\r\n"), from_utf8_slice)) >> rest: opt!(map_res!(is_not!("\r\n"), from_utf8_slice))
>> take!(1) >> take!(1)
>> ( >> (
ExtTag { tag: tag, rest: rest } ExtTag { tag, rest }
) )
) )
); );

View file

@ -54,9 +54,9 @@ pub enum Playlist {
impl Playlist { impl Playlist {
pub fn write_to<T: Write>(&self, writer: &mut T) -> std::io::Result<()> { pub fn write_to<T: Write>(&self, writer: &mut T) -> std::io::Result<()> {
match self { match *self {
&Playlist::MasterPlaylist(ref pl) => pl.write_to(writer), Playlist::MasterPlaylist(ref pl) => pl.write_to(writer),
&Playlist::MediaPlaylist(ref pl) => pl.write_to(writer), Playlist::MediaPlaylist(ref pl) => pl.write_to(writer),
} }
} }
} }
@ -87,8 +87,7 @@ impl MasterPlaylist {
} }
pub fn write_to<T: Write>(&self, w: &mut T) -> std::io::Result<()> { pub fn write_to<T: Write>(&self, w: &mut T) -> std::io::Result<()> {
writeln!(w, "{}", "#EXTM3U")?; writeln!(w, "#EXTM3U\n#EXT-X-VERSION:{}", self.version)?;
writeln!(w, "#EXT-X-VERSION:{}", self.version)?;
for alternative in &self.alternatives { for alternative in &self.alternatives {
alternative.write_to(w)?; alternative.write_to(w)?;
@ -156,7 +155,7 @@ pub struct VariantStream {
impl VariantStream { impl VariantStream {
pub fn from_hashmap(mut attrs: HashMap<String, String>, is_i_frame: bool) -> VariantStream { pub fn from_hashmap(mut attrs: HashMap<String, String>, is_i_frame: bool) -> VariantStream {
VariantStream { VariantStream {
is_i_frame: is_i_frame, is_i_frame,
uri: attrs.remove("URI").unwrap_or_else(String::new), uri: attrs.remove("URI").unwrap_or_else(String::new),
bandwidth: attrs.remove("BANDWIDTH").unwrap_or_else(String::new), bandwidth: attrs.remove("BANDWIDTH").unwrap_or_else(String::new),
average_bandwidth: attrs.remove("AVERAGE-BANDWIDTH"), average_bandwidth: attrs.remove("AVERAGE-BANDWIDTH"),
@ -182,7 +181,7 @@ impl VariantStream {
write_some_attribute_quoted!(w, ",AUDIO", &self.audio)?; write_some_attribute_quoted!(w, ",AUDIO", &self.audio)?;
write_some_attribute_quoted!(w, ",SUBTITLES", &self.subtitles)?; write_some_attribute_quoted!(w, ",SUBTITLES", &self.subtitles)?;
write_some_attribute_quoted!(w, ",CLOSED-CAPTIONS", &self.closed_captions)?; write_some_attribute_quoted!(w, ",CLOSED-CAPTIONS", &self.closed_captions)?;
write!(w, "\n")?; writeln!(w)?;
writeln!(w, "{}", self.uri) writeln!(w, "{}", self.uri)
} }
} }
@ -235,7 +234,7 @@ impl AlternativeMedia {
group_id: attrs.remove("GROUP-ID").unwrap_or_else(String::new), group_id: attrs.remove("GROUP-ID").unwrap_or_else(String::new),
language: attrs.remove("LANGUAGE"), language: attrs.remove("LANGUAGE"),
assoc_language: attrs.remove("ASSOC-LANGUAGE"), assoc_language: attrs.remove("ASSOC-LANGUAGE"),
name: attrs.remove("NAME").unwrap_or(String::new()), name: attrs.remove("NAME").unwrap_or_default(),
default: bool_default_false!(attrs.remove("DEFAULT")), default: bool_default_false!(attrs.remove("DEFAULT")),
autoselect: bool_default_false!(attrs.remove("AUTOSELECT")), autoselect: bool_default_false!(attrs.remove("AUTOSELECT")),
forced: bool_default_false!(attrs.remove("FORCED")), forced: bool_default_false!(attrs.remove("FORCED")),
@ -265,7 +264,7 @@ impl AlternativeMedia {
write_some_attribute_quoted!(w, ",INSTREAM-ID", &self.instream_id)?; write_some_attribute_quoted!(w, ",INSTREAM-ID", &self.instream_id)?;
write_some_attribute_quoted!(w, ",CHARACTERISTICS", &self.characteristics)?; write_some_attribute_quoted!(w, ",CHARACTERISTICS", &self.characteristics)?;
write_some_attribute_quoted!(w, ",CHANNELS", &self.channels)?; write_some_attribute_quoted!(w, ",CHANNELS", &self.channels)?;
write!(w, "\n") writeln!(w)
} }
} }
@ -305,11 +304,11 @@ impl fmt::Display for AlternativeMediaType {
write!( write!(
f, f,
"{}", "{}",
match self { match *self {
&AlternativeMediaType::Audio => "AUDIO", AlternativeMediaType::Audio => "AUDIO",
&AlternativeMediaType::Video => "VIDEO", AlternativeMediaType::Video => "VIDEO",
&AlternativeMediaType::Subtitles => "SUBTITLES", AlternativeMediaType::Subtitles => "SUBTITLES",
&AlternativeMediaType::ClosedCaptions => "CLOSEDCAPTIONS", AlternativeMediaType::ClosedCaptions => "CLOSEDCAPTIONS",
} }
) )
} }
@ -327,7 +326,7 @@ impl SessionKey {
pub fn write_to<T: Write>(&self, w: &mut T) -> std::io::Result<()> { pub fn write_to<T: Write>(&self, w: &mut T) -> std::io::Result<()> {
write!(w, "#EXT-X-SESSION-KEY:")?; write!(w, "#EXT-X-SESSION-KEY:")?;
self.0.write_attributes_to(w)?; self.0.write_attributes_to(w)?;
write!(w, "\n") writeln!(w)
} }
} }
@ -392,7 +391,7 @@ impl SessionData {
SessionDataField::Uri(uri) => write!(w, ",URI=\"{}\"", uri)?, SessionDataField::Uri(uri) => write!(w, ",URI=\"{}\"", uri)?,
}; };
write_some_attribute_quoted!(w, ",LANGUAGE", &self.language)?; write_some_attribute_quoted!(w, ",LANGUAGE", &self.language)?;
write!(w, "\n") writeln!(w)
} }
} }
@ -428,8 +427,7 @@ pub struct MediaPlaylist {
impl MediaPlaylist { impl MediaPlaylist {
pub fn write_to<T: Write>(&self, w: &mut T) -> std::io::Result<()> { pub fn write_to<T: Write>(&self, w: &mut T) -> std::io::Result<()> {
writeln!(w, "{}", "#EXTM3U")?; writeln!(w, "#EXTM3U\n#EXT-X-VERSION:{}", self.version)?;
writeln!(w, "#EXT-X-VERSION:{}", self.version)?;
writeln!(w, "#EXT-X-TARGETDURATION:{}", self.target_duration)?; writeln!(w, "#EXT-X-TARGETDURATION:{}", self.target_duration)?;
if self.media_sequence != 0 { if self.media_sequence != 0 {
@ -490,9 +488,9 @@ impl fmt::Display for MediaPlaylistType {
write!( write!(
f, f,
"{}", "{}",
match self { match *self {
&MediaPlaylistType::Event => "EVENT", MediaPlaylistType::Event => "EVENT",
&MediaPlaylistType::Vod => "VOD", MediaPlaylistType::Vod => "VOD",
} }
) )
} }
@ -542,20 +540,20 @@ impl MediaSegment {
if let Some(ref byte_range) = self.byte_range { if let Some(ref byte_range) = self.byte_range {
write!(w, "#EXT-X-BYTERANGE:")?; write!(w, "#EXT-X-BYTERANGE:")?;
byte_range.write_value_to(w)?; byte_range.write_value_to(w)?;
write!(w, "\n")?; writeln!(w)?;
} }
if self.discontinuity { if self.discontinuity {
writeln!(w, "{}", "#EXT-X-DISCONTINUITY")?; writeln!(w, "#EXT-X-DISCONTINUITY")?;
} }
if let Some(ref key) = self.key { if let Some(ref key) = self.key {
write!(w, "#EXT-X-KEY:")?; write!(w, "#EXT-X-KEY:")?;
key.write_attributes_to(w)?; key.write_attributes_to(w)?;
write!(w, "\n")?; writeln!(w)?;
} }
if let Some(ref map) = self.map { if let Some(ref map) = self.map {
write!(w, "#EXT-X-MAP:")?; write!(w, "#EXT-X-MAP:")?;
map.write_attributes_to(w)?; map.write_attributes_to(w)?;
write!(w, "\n")?; writeln!(w)?;
} }
if let Some(ref v) = self.program_date_time { if let Some(ref v) = self.program_date_time {
writeln!(w, "#EXT-X-PROGRAM-DATE-TIME:{}", v)?; writeln!(w, "#EXT-X-PROGRAM-DATE-TIME:{}", v)?;
@ -572,7 +570,7 @@ impl MediaSegment {
if let Some(ref v) = self.title { if let Some(ref v) = self.title {
writeln!(w, "{}", v)?; writeln!(w, "{}", v)?;
} else { } else {
write!(w, "\n")?; writeln!(w)?;
} }
writeln!(w, "{}", self.uri) writeln!(w, "{}", self.uri)
@ -704,14 +702,14 @@ impl Start {
pub fn from_hashmap(mut attrs: HashMap<String, String>) -> Start { pub fn from_hashmap(mut attrs: HashMap<String, String>) -> Start {
Start { Start {
time_offset: attrs.remove("TIME-OFFSET").unwrap_or_else(String::new), time_offset: attrs.remove("TIME-OFFSET").unwrap_or_else(String::new),
precise: attrs.remove("PRECISE").or(Some("NO".to_string())), precise: attrs.remove("PRECISE").or_else(|| Some("NO".to_string())),
} }
} }
pub fn write_to<T: Write>(&self, w: &mut T) -> std::io::Result<()> { pub fn write_to<T: Write>(&self, w: &mut T) -> std::io::Result<()> {
write!(w, "#EXT-X-START:TIME-OFFSET={}", self.time_offset)?; write!(w, "#EXT-X-START:TIME-OFFSET={}", self.time_offset)?;
write_some_attribute!(w, ",PRECISE", &self.precise)?; write_some_attribute!(w, ",PRECISE", &self.precise)?;
write!(w, "\n") writeln!(w)
} }
} }