Skip to content

Commit a432900

Browse files
committed
Fix nightly clippy warnings.
1 parent aaad770 commit a432900

File tree

6 files changed

+34
-69
lines changed

6 files changed

+34
-69
lines changed

mp4parse/src/lib.rs

Lines changed: 9 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -852,7 +852,7 @@ pub enum Error {
852852

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

@@ -1533,7 +1533,7 @@ impl fmt::Debug for IsobmffItem {
15331533
match &self {
15341534
IsobmffItem::MdatLocation(extent) | IsobmffItem::IdatLocation(extent) => f
15351535
.debug_struct("IsobmffItem::Location")
1536-
.field("0", &format_args!("{:?}", extent))
1536+
.field("0", &format_args!("{extent:?}"))
15371537
.finish(),
15381538
IsobmffItem::Data(data) => f
15391539
.debug_struct("IsobmffItem::Data")
@@ -2139,38 +2139,28 @@ enum Extent {
21392139
ToEnd { offset: u64 },
21402140
}
21412141

2142-
#[derive(Debug, PartialEq, Eq)]
2142+
#[derive(Debug, PartialEq, Eq, Default)]
21432143
pub enum TrackType {
21442144
Audio,
21452145
Video,
21462146
Picture,
21472147
AuxiliaryVideo,
21482148
Metadata,
2149+
#[default]
21492150
Unknown,
21502151
}
21512152

2152-
impl Default for TrackType {
2153-
fn default() -> Self {
2154-
TrackType::Unknown
2155-
}
2156-
}
2157-
21582153
// This type is used by mp4parse_capi since it needs to be passed from FFI consumers
21592154
// The C-visible struct is renamed via mp4parse_capi/cbindgen.toml to match naming conventions
21602155
#[repr(C)]
2161-
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
2156+
#[derive(Clone, Copy, Debug, PartialEq, Eq, Default)]
21622157
pub enum ParseStrictness {
21632158
Permissive, // Error only on ambiguous inputs
2164-
Normal, // Error on "shall" directives, log warnings for "should"
2159+
#[default]
2160+
Normal, // Error on "shall" directives, log warnings for "should"
21652161
Strict, // Error on "should" directives
21662162
}
21672163

2168-
impl Default for ParseStrictness {
2169-
fn default() -> Self {
2170-
ParseStrictness::Normal
2171-
}
2172-
}
2173-
21742164
fn fail_with_status_if(violation: bool, status: Status) -> Result<()> {
21752165
let error = Error::from(status);
21762166
if violation {
@@ -2181,8 +2171,9 @@ fn fail_with_status_if(violation: bool, status: Status) -> Result<()> {
21812171
}
21822172
}
21832173

2184-
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
2174+
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
21852175
pub enum CodecType {
2176+
#[default]
21862177
Unknown,
21872178
MP3,
21882179
AAC,
@@ -2204,12 +2195,6 @@ pub enum CodecType {
22042195
AMRWB,
22052196
}
22062197

2207-
impl Default for CodecType {
2208-
fn default() -> Self {
2209-
CodecType::Unknown
2210-
}
2211-
}
2212-
22132198
/// The media's global (mvhd) timescale in units per second.
22142199
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
22152200
pub struct MediaTimeScale(pub u64);

mp4parse/src/tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1104,7 +1104,7 @@ fn read_stsd_mp4v() {
11041104
let esds_specific_data = &mp4v[90..];
11051105
#[cfg(feature = "mp4v")]
11061106
let esds_specific_data = &mp4v[112..151];
1107-
println!("esds_specific_data {:?}", esds_specific_data);
1107+
println!("esds_specific_data {esds_specific_data:?}");
11081108

11091109
let mut stream = make_box(BoxSize::Auto, b"mp4v", |s| s.append_bytes(mp4v.as_slice()));
11101110
let mut iter = super::BoxIter::new(&mut stream);

mp4parse/src/unstable.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ pub fn create_sample_table(
146146
};
147147

148148
let (stsc, stco, stsz, stts) = match (&track.stsc, &track.stco, &track.stsz, &track.stts) {
149-
(&Some(ref a), &Some(ref b), &Some(ref c), &Some(ref d)) => (a, b, c, d),
149+
(Some(a), Some(b), Some(c), Some(d)) => (a, b, c, d),
150150
_ => return None,
151151
};
152152

mp4parse/tests/public.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1288,7 +1288,7 @@ fn public_avif_read_samples_impl(strictness: ParseStrictness) {
12881288
let path = entry.path();
12891289
let extension = path.extension().unwrap_or_default();
12901290
if !path.is_file() || (extension != "avif" && extension != "avifs") {
1291-
eprintln!("Skipping {:?}", path);
1291+
eprintln!("Skipping {path:?}");
12921292
continue; // Skip directories, ReadMe.txt, etc.
12931293
}
12941294
let corrupt = (path.canonicalize().unwrap().parent().unwrap()
@@ -1318,10 +1318,10 @@ fn public_avif_read_samples_impl(strictness: ParseStrictness) {
13181318
"{:?}",
13191319
c.unsupported_features
13201320
);
1321-
eprintln!("Successfully parsed {:?}", path)
1321+
eprintln!("Successfully parsed {path:?}")
13221322
}
13231323
Err(e) if corrupt => {
1324-
eprintln!("Expected error parsing corrupt input {:?}: {:?}", path, e)
1324+
eprintln!("Expected error parsing corrupt input {path:?}: {e:?}")
13251325
}
13261326
Err(e) => panic!("Unexpected error parsing {:?}: {:?}", path, e),
13271327
}

mp4parse_capi/examples/dump.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ fn dump_avif(filename: &str, strictness: ParseStrictness) {
2424
unsafe {
2525
let mut parser = std::ptr::null_mut();
2626
let rv = mp4parse_avif_new(&io, strictness, &mut parser);
27-
println!("mp4parse_avif_new -> {:?}", rv);
27+
println!("mp4parse_avif_new -> {rv:?}");
2828
if rv == Mp4parseStatus::Ok {
2929
println!(
3030
"mp4parse_avif_get_image_safe -> {:?}",
@@ -52,18 +52,18 @@ fn dump_file(filename: &str, strictness: ParseStrictness) {
5252
dump_avif(filename, strictness);
5353
}
5454
_ => {
55-
println!("-- fail to parse: {:?}, '-v' for more info", rv);
55+
println!("-- fail to parse: {rv:?}, '-v' for more info");
5656
return;
5757
}
5858
}
5959

6060
let mut frag_info = Mp4parseFragmentInfo::default();
6161
match mp4parse_get_fragment_info(parser, &mut frag_info) {
6262
Mp4parseStatus::Ok => {
63-
println!("-- mp4parse_fragment_info {:?}", frag_info);
63+
println!("-- mp4parse_fragment_info {frag_info:?}");
6464
}
6565
rv => {
66-
println!("-- mp4parse_fragment_info failed with {:?}", rv);
66+
println!("-- mp4parse_fragment_info failed with {rv:?}");
6767
return;
6868
}
6969
}
@@ -84,10 +84,10 @@ fn dump_file(filename: &str, strictness: ParseStrictness) {
8484
};
8585
match mp4parse_get_track_info(parser, i, &mut track_info) {
8686
Mp4parseStatus::Ok => {
87-
println!("-- mp4parse_get_track_info {:?}", track_info);
87+
println!("-- mp4parse_get_track_info {track_info:?}");
8888
}
8989
_ => {
90-
println!("-- mp4parse_get_track_info failed, track id: {}", i);
90+
println!("-- mp4parse_get_track_info failed, track id: {i}");
9191
return;
9292
}
9393
}
@@ -97,7 +97,7 @@ fn dump_file(filename: &str, strictness: ParseStrictness) {
9797
let mut audio_info = Mp4parseTrackAudioInfo::default();
9898
match mp4parse_get_track_audio_info(parser, i, &mut audio_info) {
9999
Mp4parseStatus::Ok => {
100-
println!("-- mp4parse_get_track_audio_info {:?}", audio_info);
100+
println!("-- mp4parse_get_track_audio_info {audio_info:?}");
101101
for i in 0..audio_info.sample_info_count as isize {
102102
let sample_info = audio_info.sample_info.offset(i);
103103
println!(
@@ -107,7 +107,7 @@ fn dump_file(filename: &str, strictness: ParseStrictness) {
107107
}
108108
}
109109
_ => {
110-
println!("-- mp4parse_get_track_audio_info failed, track id: {}", i);
110+
println!("-- mp4parse_get_track_audio_info failed, track id: {i}");
111111
return;
112112
}
113113
}
@@ -118,7 +118,7 @@ fn dump_file(filename: &str, strictness: ParseStrictness) {
118118
let mut video_info = Mp4parseTrackVideoInfo::default();
119119
match mp4parse_get_track_video_info(parser, i, &mut video_info) {
120120
Mp4parseStatus::Ok => {
121-
println!("-- mp4parse_get_track_video_info {:?}", video_info);
121+
println!("-- mp4parse_get_track_video_info {video_info:?}");
122122
for i in 0..video_info.sample_info_count as isize {
123123
let sample_info = video_info.sample_info.offset(i);
124124
println!(
@@ -128,7 +128,7 @@ fn dump_file(filename: &str, strictness: ParseStrictness) {
128128
}
129129
}
130130
_ => {
131-
println!("-- mp4parse_get_track_video_info failed, track id: {}", i);
131+
println!("-- mp4parse_get_track_video_info failed, track id: {i}");
132132
return;
133133
}
134134
}
@@ -172,7 +172,7 @@ fn main() {
172172
"-v" | "--verbose" => verbose = true,
173173
_ => {
174174
if let Some("-") = arg.get(0..1) {
175-
eprintln!("Ignoring unknown switch {:?}", arg);
175+
eprintln!("Ignoring unknown switch {arg:?}");
176176
} else {
177177
filenames.push(arg)
178178
}

mp4parse_capi/src/lib.rs

Lines changed: 9 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -72,25 +72,21 @@ struct HashMap;
7272
struct String;
7373

7474
#[repr(C)]
75-
#[derive(PartialEq, Eq, Debug)]
75+
#[derive(PartialEq, Eq, Debug, Default)]
7676
pub enum Mp4parseTrackType {
77+
#[default]
7778
Video = 0,
7879
Picture = 1,
7980
AuxiliaryVideo = 2,
8081
Audio = 3,
8182
Metadata = 4,
8283
}
8384

84-
impl Default for Mp4parseTrackType {
85-
fn default() -> Self {
86-
Mp4parseTrackType::Video
87-
}
88-
}
89-
9085
#[allow(non_camel_case_types, clippy::upper_case_acronyms)]
9186
#[repr(C)]
92-
#[derive(PartialEq, Eq, Debug)]
87+
#[derive(PartialEq, Eq, Debug, Default)]
9388
pub enum Mp4parseCodec {
89+
#[default]
9490
Unknown,
9591
Aac,
9692
Flac,
@@ -111,15 +107,10 @@ pub enum Mp4parseCodec {
111107
AMRWB,
112108
}
113109

114-
impl Default for Mp4parseCodec {
115-
fn default() -> Self {
116-
Mp4parseCodec::Unknown
117-
}
118-
}
119-
120110
#[repr(C)]
121-
#[derive(PartialEq, Eq, Debug)]
111+
#[derive(PartialEq, Eq, Debug, Default)]
122112
pub enum Mp4ParseEncryptionSchemeType {
113+
#[default]
123114
None,
124115
Cenc,
125116
Cbc1,
@@ -130,12 +121,6 @@ pub enum Mp4ParseEncryptionSchemeType {
130121
// be exposed in future, should the spec change.
131122
}
132123

133-
impl Default for Mp4ParseEncryptionSchemeType {
134-
fn default() -> Self {
135-
Mp4ParseEncryptionSchemeType::None
136-
}
137-
}
138-
139124
#[repr(C)]
140125
#[derive(Default, Debug)]
141126
pub struct Mp4parseTrackInfo {
@@ -313,19 +298,14 @@ pub struct Mp4parseParser {
313298
}
314299

315300
#[repr(C)]
316-
#[derive(Debug)]
301+
#[derive(Debug, Default)]
317302
pub enum Mp4parseAvifLoopMode {
303+
#[default]
318304
NoEdits,
319305
LoopByCount,
320306
LoopInfinitely,
321307
}
322308

323-
impl Default for Mp4parseAvifLoopMode {
324-
fn default() -> Self {
325-
Mp4parseAvifLoopMode::NoEdits
326-
}
327-
}
328-
329309
#[repr(C)]
330310
#[derive(Debug)]
331311
pub struct Mp4parseAvifInfo {
@@ -1482,7 +1462,7 @@ pub unsafe extern "C" fn mp4parse_is_fragmented(
14821462
iter.find(|track| track.track_id == Some(track_id))
14831463
.map_or(Mp4parseStatus::BadArg, |track| {
14841464
match (&track.stsc, &track.stco, &track.stts) {
1485-
(&Some(ref stsc), &Some(ref stco), &Some(ref stts))
1465+
(Some(stsc), Some(stco), Some(stts))
14861466
if stsc.samples.is_empty()
14871467
&& stco.offsets.is_empty()
14881468
&& stts.samples.is_empty() =>

0 commit comments

Comments
 (0)