cargo fmt + clippy --fix: 104 format violations fixed, 8 clippy auto-fixes

This commit is contained in:
MattJackson
2026-04-11 19:10:20 +00:00
parent c91d6e371f
commit d56dd934bb
27 changed files with 831 additions and 378 deletions
+3 -4
View File
@@ -87,9 +87,8 @@ pub fn find_dts_hd_ext_sync(data: &[u8]) -> Option<usize> {
/// ((ext[6] & 0x1F) << 11) | (ext[7] << 3) | (ext[8] >> 5) + 1
pub fn dts_hd_ext_frame_size(ext: &[u8]) -> usize {
debug_assert!(ext.len() >= 9);
let raw = ((ext[6] as usize & 0x1F) << 11)
| ((ext[7] as usize) << 3)
| ((ext[8] as usize) >> 5);
let raw =
((ext[6] as usize & 0x1F) << 11) | ((ext[7] as usize) << 3) | ((ext[8] as usize) >> 5);
raw + 1
}
@@ -218,7 +217,7 @@ mod tests {
fn parse_core_plus_extension_truncated_at_buffer_end() {
let mut parser = DtsParser::new();
let core = make_dts_core(4); // 8 bytes
// Extension claims 200 bytes but we only provide 20
// Extension claims 200 bytes but we only provide 20
let ext = make_dts_hd_ext(199, 0xDD); // wants 200 bytes
let mut data = core;
// Only append partial extension (first 20 bytes)
+28 -9
View File
@@ -115,7 +115,10 @@ mod tests {
let frames = parser.parse(&pes);
assert_eq!(frames.len(), 1);
assert_eq!(frames[0].data, sub_data, "VobSub data should pass through unmodified");
assert_eq!(
frames[0].data, sub_data,
"VobSub data should pass through unmodified"
);
assert_eq!(frames[0].pts_ns, 1_000_000_000);
}
@@ -127,7 +130,10 @@ mod tests {
let pes = make_pes(data, Some(90000 * i as i64));
let frames = parser.parse(&pes);
assert_eq!(frames.len(), 1);
assert!(frames[0].keyframe, "DVD subtitle frames should always be keyframes");
assert!(
frames[0].keyframe,
"DVD subtitle frames should always be keyframes"
);
}
}
@@ -224,24 +230,37 @@ mod tests {
];
let result = format_palette(&palette);
let text = String::from_utf8(result).unwrap();
assert!(text.starts_with("palette: "), "should start with 'palette: '");
assert!(
text.starts_with("palette: "),
"should start with 'palette: '"
);
assert!(text.ends_with('\n'), "should end with newline");
// First color: 000000
assert!(text.contains("000000"), "black should be 000000, got: {}", text);
assert!(
text.contains("000000"),
"black should be 000000, got: {}",
text
);
// Second color: ffffff
assert!(text.contains("ffffff"), "white should be ffffff, got: {}", text);
assert!(
text.contains("ffffff"),
"white should be ffffff, got: {}",
text
);
}
#[test]
fn format_palette_16_colors() {
let palette: Vec<[u8; 4]> = (0..16)
.map(|i| [0x00, (i * 16) as u8, 128, 128])
.collect();
let palette: Vec<[u8; 4]> = (0..16).map(|i| [0x00, (i * 16) as u8, 128, 128]).collect();
let result = format_palette(&palette);
let text = String::from_utf8(result).unwrap();
// Should have exactly 15 commas (16 colors separated by ", ")
let comma_count = text.matches(", ").count();
assert_eq!(comma_count, 15, "16 colors should have 15 separators, got {}", comma_count);
assert_eq!(
comma_count, 15,
"16 colors should have 15 separators, got {}",
comma_count
);
}
#[test]
+6 -2
View File
@@ -525,7 +525,9 @@ mod tests {
let mut nal_types = Vec::new();
let mut offset = 0;
while offset + 4 <= fd.len() {
let length = u32::from_be_bytes([fd[offset], fd[offset + 1], fd[offset + 2], fd[offset + 3]]) as usize;
let length =
u32::from_be_bytes([fd[offset], fd[offset + 1], fd[offset + 2], fd[offset + 3]])
as usize;
offset += 4;
assert!(offset + length <= fd.len(), "NAL length exceeds frame data");
let nal_type = (fd[offset] >> 1) & 0x3F;
@@ -553,7 +555,9 @@ mod tests {
// Verify RPU payload is intact
let mut offset = 0;
while offset + 4 <= fd.len() {
let length = u32::from_be_bytes([fd[offset], fd[offset + 1], fd[offset + 2], fd[offset + 3]]) as usize;
let length =
u32::from_be_bytes([fd[offset], fd[offset + 1], fd[offset + 2], fd[offset + 3]])
as usize;
offset += 4;
let nal_type = (fd[offset] >> 1) & 0x3F;
if nal_type == 62 {
+10 -8
View File
@@ -39,10 +39,10 @@ const FRAME_RATES: [(u32, u32); 9] = [
/// Aspect ratio table (index from sequence header aspect_ratio_information).
const ASPECT_RATIOS: [(u8, u8); 5] = [
(0, 0), // 0: forbidden
(1, 1), // 1: square pixels (1:1 SAR)
(4, 3), // 2: 4:3 display
(16, 9), // 3: 16:9 display
(0, 0), // 0: forbidden
(1, 1), // 1: square pixels (1:1 SAR)
(4, 3), // 2: 4:3 display
(16, 9), // 3: 16:9 display
(221, 100), // 4: 2.21:1 display
];
@@ -114,8 +114,7 @@ impl CodecParser for Mpeg2Parser {
// Check if sequence extension follows immediately.
if hdr_end + 3 < data.len() && data[hdr_end + 3] == SEQ_EXT_CODE {
let ext_end =
find_start_code(data, hdr_end + 4).unwrap_or(data.len());
let ext_end = find_start_code(data, hdr_end + 4).unwrap_or(data.len());
seq_data.extend_from_slice(&data[hdr_end..ext_end]);
}
@@ -344,7 +343,10 @@ mod tests {
let _frames = parser.parse(&pes);
let cp = parser.codec_private();
assert!(cp.is_some(), "codec_private should be available after sequence header");
assert!(
cp.is_some(),
"codec_private should be available after sequence header"
);
let cp = cp.unwrap();
// Should start with the sequence header start code.
assert_eq!(&cp[..4], &[0x00, 0x00, 0x01, SEQ_HEADER_CODE]);
@@ -368,7 +370,7 @@ mod tests {
// Sequence extension: 00 00 01 B5 [ext data]
data.extend_from_slice(&[0x00, 0x00, 0x01, SEQ_EXT_CODE]);
data.extend_from_slice(&[0x14, 0x8A, 0x00, 0x01, 0x00, 0x00]); // ext payload
// Picture header follows.
// Picture header follows.
data.extend_from_slice(&make_picture_header(PICTURE_TYPE_I));
data.extend_from_slice(&[0xFF; 4]);