Fix all clippy warnings: dead code, match patterns, type complexity, docs

- Remove unused pes_buf field from M2tsStream and unused TS_PACKET/BD_TS_PACKET constants
- Replace match-with-single-pattern with if let (3 instances in drive/mod.rs)
- Replace match-can-be-? with ? operator for scsi::open call
- Add type aliases PesSetup and MkvHeaderResult to reduce type complexity
- Collapse identical if/else branches in tsmux.rs build_pes_header
- Use RangeInclusive::contains instead of manual range checks
- Make WriteSeek trait pub (was pub(crate) but leaked through pub fn)
- Remove empty line after doc comment in disc.rs
- Fix doc list item indentation in scsi/linux.rs (12 instances)
This commit is contained in:
MattJackson
2026-04-15 04:09:56 +00:00
parent 8ae05bc388
commit 1a9956cea0
7 changed files with 44 additions and 63 deletions
-1
View File
@@ -166,7 +166,6 @@ impl DiscStream {
}
/// Set SCSI read timeout (default 30s).
fn new(drive: Drive, title: DiscTitle, mode: ReadMode, max_batch: u16) -> Self {
// Set up PES demux from title stream PIDs
let mut pids = Vec::new();
+3 -5
View File
@@ -7,6 +7,8 @@ use super::{meta, ts, IOStream, ReadSeek};
use crate::disc::{DiscTitle, Stream as DiscStream};
use std::io::{self, Read, Seek, SeekFrom, Write};
type PesSetup = (Vec<u16>, Vec<(u16, Box<dyn super::codec::CodecParser>)>, Vec<(u16, usize)>);
/// Size of initial scan buffer for PMT/stream detection.
const SCAN_SIZE: usize = 1024 * 1024;
@@ -32,7 +34,6 @@ pub struct M2tsStream {
parsers: Vec<(u16, Box<dyn super::codec::CodecParser>)>,
pending_frames: std::collections::VecDeque<crate::pes::PesFrame>,
pid_to_track: Vec<(u16, usize)>,
pes_buf: Vec<u8>,
pes_eof: bool,
}
@@ -51,12 +52,11 @@ impl M2tsStream {
parsers: Vec::new(),
pending_frames: std::collections::VecDeque::new(),
pid_to_track: Vec::new(),
pes_buf: Vec::new(),
pes_eof: false,
}
}
fn setup_pes(streams: &[DiscStream]) -> (Vec<u16>, Vec<(u16, Box<dyn super::codec::CodecParser>)>, Vec<(u16, usize)>) {
fn setup_pes(streams: &[DiscStream]) -> PesSetup {
let mut pids = Vec::new();
let mut parsers: Vec<(u16, Box<dyn super::codec::CodecParser>)> = Vec::new();
let mut pid_to_track = Vec::new();
@@ -104,7 +104,6 @@ impl M2tsStream {
parsers,
pending_frames: std::collections::VecDeque::new(),
pid_to_track,
pes_buf: vec![0u8; 192 * 1024],
pes_eof: false,
});
}
@@ -144,7 +143,6 @@ impl M2tsStream {
parsers,
pending_frames: std::collections::VecDeque::new(),
pid_to_track,
pes_buf: vec![0u8; 192 * 1024],
pes_eof: false,
})
}
+3 -1
View File
@@ -8,6 +8,8 @@ use super::lookahead::{LookaheadBuffer, LookaheadState, DEFAULT_LOOKAHEAD_SIZE};
use super::mkv::{MkvMuxer, MkvTrack};
use super::ts::TsDemuxer;
use super::{ebml, IOStream, ReadSeek, WriteSeek};
type MkvHeaderResult = io::Result<(crate::disc::DiscTitle, Vec<(u16, Vec<u8>)>)>;
use crate::disc::*;
use std::io::{self, Read, Seek, SeekFrom, Write};
@@ -462,7 +464,7 @@ fn write_pes(
/// Returns (DiscTitle, codec_privates: Vec<(track_number, codec_private_bytes)>)
fn parse_mkv_header(
r: &mut (impl Read + Seek),
) -> io::Result<(DiscTitle, Vec<(u16, Vec<u8>)>)> {
) -> MkvHeaderResult {
let mut title = String::new();
let mut duration_ms = 0.0f64;
let mut ts_scale: u64 = 1_000_000;
+1 -1
View File
@@ -79,5 +79,5 @@ pub trait IOStream: Read + Write {
pub(crate) trait ReadSeek: Read + Seek {}
impl<T: Read + Seek> ReadSeek for T {}
pub(crate) trait WriteSeek: Write + Seek {}
pub trait WriteSeek: Write + Seek {}
impl<T: Write + Seek> WriteSeek for T {}
+2 -8
View File
@@ -8,8 +8,6 @@ use std::io::{self, Write};
const SYNC_BYTE: u8 = 0x47;
const TS_PAYLOAD: usize = 184;
const TS_PACKET: usize = 188;
const BD_TS_PACKET: usize = 192;
pub struct TsMuxer<W: Write> {
writer: W,
@@ -112,14 +110,10 @@ impl<W: Write> TsMuxer<W> {
/// Build a PES packet header for a BD stream.
fn build_pes_header(pid: u16, pts_90k: u64, data_len: usize) -> Vec<u8> {
// Determine stream_id from PID range
let stream_id: u8 = if pid >= 0x1011 && pid <= 0x101F {
let stream_id: u8 = if (0x1011..=0x101F).contains(&pid) {
0xE0 // video
} else if pid >= 0x1100 && pid <= 0x111F {
0xBD // audio (private stream 1)
} else if pid >= 0x1200 && pid <= 0x121F {
0xBD // PGS subtitle
} else {
0xBD // default
0xBD // audio, PGS subtitle, or default (private stream 1)
};
let pes_data_len = data_len + 8; // 3 header bytes + 5 PTS bytes + data