Skip to content

Commit

Permalink
Fix nightly clippy warnings.
Browse files Browse the repository at this point in the history
  • Loading branch information
kinetiknz committed Jan 22, 2023
1 parent aaad770 commit a432900
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 69 deletions.
33 changes: 9 additions & 24 deletions mp4parse/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -852,7 +852,7 @@ pub enum Error {

impl std::fmt::Display for Error {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{:?}", self)
write!(f, "{self:?}")
}
}

Expand Down Expand Up @@ -1533,7 +1533,7 @@ impl fmt::Debug for IsobmffItem {
match &self {
IsobmffItem::MdatLocation(extent) | IsobmffItem::IdatLocation(extent) => f
.debug_struct("IsobmffItem::Location")
.field("0", &format_args!("{:?}", extent))
.field("0", &format_args!("{extent:?}"))
.finish(),
IsobmffItem::Data(data) => f
.debug_struct("IsobmffItem::Data")
Expand Down Expand Up @@ -2139,38 +2139,28 @@ enum Extent {
ToEnd { offset: u64 },
}

#[derive(Debug, PartialEq, Eq)]
#[derive(Debug, PartialEq, Eq, Default)]
pub enum TrackType {
Audio,
Video,
Picture,
AuxiliaryVideo,
Metadata,
#[default]
Unknown,
}

impl Default for TrackType {
fn default() -> Self {
TrackType::Unknown
}
}

// This type is used by mp4parse_capi since it needs to be passed from FFI consumers
// The C-visible struct is renamed via mp4parse_capi/cbindgen.toml to match naming conventions
#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Default)]
pub enum ParseStrictness {
Permissive, // Error only on ambiguous inputs
Normal, // Error on "shall" directives, log warnings for "should"
#[default]
Normal, // Error on "shall" directives, log warnings for "should"
Strict, // Error on "should" directives
}

impl Default for ParseStrictness {
fn default() -> Self {
ParseStrictness::Normal
}
}

fn fail_with_status_if(violation: bool, status: Status) -> Result<()> {
let error = Error::from(status);
if violation {
Expand All @@ -2181,8 +2171,9 @@ fn fail_with_status_if(violation: bool, status: Status) -> Result<()> {
}
}

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum CodecType {
#[default]
Unknown,
MP3,
AAC,
Expand All @@ -2204,12 +2195,6 @@ pub enum CodecType {
AMRWB,
}

impl Default for CodecType {
fn default() -> Self {
CodecType::Unknown
}
}

/// The media's global (mvhd) timescale in units per second.
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
pub struct MediaTimeScale(pub u64);
Expand Down
2 changes: 1 addition & 1 deletion mp4parse/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1104,7 +1104,7 @@ fn read_stsd_mp4v() {
let esds_specific_data = &mp4v[90..];
#[cfg(feature = "mp4v")]
let esds_specific_data = &mp4v[112..151];
println!("esds_specific_data {:?}", esds_specific_data);
println!("esds_specific_data {esds_specific_data:?}");

let mut stream = make_box(BoxSize::Auto, b"mp4v", |s| s.append_bytes(mp4v.as_slice()));
let mut iter = super::BoxIter::new(&mut stream);
Expand Down
2 changes: 1 addition & 1 deletion mp4parse/src/unstable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ pub fn create_sample_table(
};

let (stsc, stco, stsz, stts) = match (&track.stsc, &track.stco, &track.stsz, &track.stts) {
(&Some(ref a), &Some(ref b), &Some(ref c), &Some(ref d)) => (a, b, c, d),
(Some(a), Some(b), Some(c), Some(d)) => (a, b, c, d),
_ => return None,
};

Expand Down
6 changes: 3 additions & 3 deletions mp4parse/tests/public.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1288,7 +1288,7 @@ fn public_avif_read_samples_impl(strictness: ParseStrictness) {
let path = entry.path();
let extension = path.extension().unwrap_or_default();
if !path.is_file() || (extension != "avif" && extension != "avifs") {
eprintln!("Skipping {:?}", path);
eprintln!("Skipping {path:?}");
continue; // Skip directories, ReadMe.txt, etc.
}
let corrupt = (path.canonicalize().unwrap().parent().unwrap()
Expand Down Expand Up @@ -1318,10 +1318,10 @@ fn public_avif_read_samples_impl(strictness: ParseStrictness) {
"{:?}",
c.unsupported_features
);
eprintln!("Successfully parsed {:?}", path)
eprintln!("Successfully parsed {path:?}")
}
Err(e) if corrupt => {
eprintln!("Expected error parsing corrupt input {:?}: {:?}", path, e)
eprintln!("Expected error parsing corrupt input {path:?}: {e:?}")
}
Err(e) => panic!("Unexpected error parsing {:?}: {:?}", path, e),
}
Expand Down
22 changes: 11 additions & 11 deletions mp4parse_capi/examples/dump.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ fn dump_avif(filename: &str, strictness: ParseStrictness) {
unsafe {
let mut parser = std::ptr::null_mut();
let rv = mp4parse_avif_new(&io, strictness, &mut parser);
println!("mp4parse_avif_new -> {:?}", rv);
println!("mp4parse_avif_new -> {rv:?}");
if rv == Mp4parseStatus::Ok {
println!(
"mp4parse_avif_get_image_safe -> {:?}",
Expand Down Expand Up @@ -52,18 +52,18 @@ fn dump_file(filename: &str, strictness: ParseStrictness) {
dump_avif(filename, strictness);
}
_ => {
println!("-- fail to parse: {:?}, '-v' for more info", rv);
println!("-- fail to parse: {rv:?}, '-v' for more info");
return;
}
}

let mut frag_info = Mp4parseFragmentInfo::default();
match mp4parse_get_fragment_info(parser, &mut frag_info) {
Mp4parseStatus::Ok => {
println!("-- mp4parse_fragment_info {:?}", frag_info);
println!("-- mp4parse_fragment_info {frag_info:?}");
}
rv => {
println!("-- mp4parse_fragment_info failed with {:?}", rv);
println!("-- mp4parse_fragment_info failed with {rv:?}");
return;
}
}
Expand All @@ -84,10 +84,10 @@ fn dump_file(filename: &str, strictness: ParseStrictness) {
};
match mp4parse_get_track_info(parser, i, &mut track_info) {
Mp4parseStatus::Ok => {
println!("-- mp4parse_get_track_info {:?}", track_info);
println!("-- mp4parse_get_track_info {track_info:?}");
}
_ => {
println!("-- mp4parse_get_track_info failed, track id: {}", i);
println!("-- mp4parse_get_track_info failed, track id: {i}");
return;
}
}
Expand All @@ -97,7 +97,7 @@ fn dump_file(filename: &str, strictness: ParseStrictness) {
let mut audio_info = Mp4parseTrackAudioInfo::default();
match mp4parse_get_track_audio_info(parser, i, &mut audio_info) {
Mp4parseStatus::Ok => {
println!("-- mp4parse_get_track_audio_info {:?}", audio_info);
println!("-- mp4parse_get_track_audio_info {audio_info:?}");
for i in 0..audio_info.sample_info_count as isize {
let sample_info = audio_info.sample_info.offset(i);
println!(
Expand All @@ -107,7 +107,7 @@ fn dump_file(filename: &str, strictness: ParseStrictness) {
}
}
_ => {
println!("-- mp4parse_get_track_audio_info failed, track id: {}", i);
println!("-- mp4parse_get_track_audio_info failed, track id: {i}");
return;
}
}
Expand All @@ -118,7 +118,7 @@ fn dump_file(filename: &str, strictness: ParseStrictness) {
let mut video_info = Mp4parseTrackVideoInfo::default();
match mp4parse_get_track_video_info(parser, i, &mut video_info) {
Mp4parseStatus::Ok => {
println!("-- mp4parse_get_track_video_info {:?}", video_info);
println!("-- mp4parse_get_track_video_info {video_info:?}");
for i in 0..video_info.sample_info_count as isize {
let sample_info = video_info.sample_info.offset(i);
println!(
Expand All @@ -128,7 +128,7 @@ fn dump_file(filename: &str, strictness: ParseStrictness) {
}
}
_ => {
println!("-- mp4parse_get_track_video_info failed, track id: {}", i);
println!("-- mp4parse_get_track_video_info failed, track id: {i}");
return;
}
}
Expand Down Expand Up @@ -172,7 +172,7 @@ fn main() {
"-v" | "--verbose" => verbose = true,
_ => {
if let Some("-") = arg.get(0..1) {
eprintln!("Ignoring unknown switch {:?}", arg);
eprintln!("Ignoring unknown switch {arg:?}");
} else {
filenames.push(arg)
}
Expand Down
38 changes: 9 additions & 29 deletions mp4parse_capi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,25 +72,21 @@ struct HashMap;
struct String;

#[repr(C)]
#[derive(PartialEq, Eq, Debug)]
#[derive(PartialEq, Eq, Debug, Default)]
pub enum Mp4parseTrackType {
#[default]
Video = 0,
Picture = 1,
AuxiliaryVideo = 2,
Audio = 3,
Metadata = 4,
}

impl Default for Mp4parseTrackType {
fn default() -> Self {
Mp4parseTrackType::Video
}
}

#[allow(non_camel_case_types, clippy::upper_case_acronyms)]
#[repr(C)]
#[derive(PartialEq, Eq, Debug)]
#[derive(PartialEq, Eq, Debug, Default)]
pub enum Mp4parseCodec {
#[default]
Unknown,
Aac,
Flac,
Expand All @@ -111,15 +107,10 @@ pub enum Mp4parseCodec {
AMRWB,
}

impl Default for Mp4parseCodec {
fn default() -> Self {
Mp4parseCodec::Unknown
}
}

#[repr(C)]
#[derive(PartialEq, Eq, Debug)]
#[derive(PartialEq, Eq, Debug, Default)]
pub enum Mp4ParseEncryptionSchemeType {
#[default]
None,
Cenc,
Cbc1,
Expand All @@ -130,12 +121,6 @@ pub enum Mp4ParseEncryptionSchemeType {
// be exposed in future, should the spec change.
}

impl Default for Mp4ParseEncryptionSchemeType {
fn default() -> Self {
Mp4ParseEncryptionSchemeType::None
}
}

#[repr(C)]
#[derive(Default, Debug)]
pub struct Mp4parseTrackInfo {
Expand Down Expand Up @@ -313,19 +298,14 @@ pub struct Mp4parseParser {
}

#[repr(C)]
#[derive(Debug)]
#[derive(Debug, Default)]
pub enum Mp4parseAvifLoopMode {
#[default]
NoEdits,
LoopByCount,
LoopInfinitely,
}

impl Default for Mp4parseAvifLoopMode {
fn default() -> Self {
Mp4parseAvifLoopMode::NoEdits
}
}

#[repr(C)]
#[derive(Debug)]
pub struct Mp4parseAvifInfo {
Expand Down Expand Up @@ -1482,7 +1462,7 @@ pub unsafe extern "C" fn mp4parse_is_fragmented(
iter.find(|track| track.track_id == Some(track_id))
.map_or(Mp4parseStatus::BadArg, |track| {
match (&track.stsc, &track.stco, &track.stts) {
(&Some(ref stsc), &Some(ref stco), &Some(ref stts))
(Some(stsc), Some(stco), Some(stts))
if stsc.samples.is_empty()
&& stco.offsets.is_empty()
&& stts.samples.is_empty() =>
Expand Down

0 comments on commit a432900

Please sign in to comment.