Skip to content

Commit 7b6441e

Browse files
committed
Fix clippy warnings about elided lifetimes and some rustdoc issues.
Bump the version Simplify some of the BooleanVector equality tests
1 parent 1ba7631 commit 7b6441e

10 files changed

Lines changed: 36 additions & 52 deletions

File tree

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "image-rider"
3-
version = "0.10.1"
3+
version = "0.10.2"
44
edition = "2021"
55
authors = ["Joshua Gerrish <jgerrish@gmail.com>"]
66
description = "Disk image and ROM image parser"

src/disk_format/apple/catalog.rs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ impl<'a> Serializer<'a> for TrackSectorList<'a> {
186186
pub type TrackSectorLists<'a> = Vec<TrackSectorList<'a>>;
187187

188188
/// Parse a track / sector list.
189-
pub fn parse_track_sector_list(i: &[u8]) -> IResult<&[u8], TrackSectorList> {
189+
pub fn parse_track_sector_list(i: &[u8]) -> IResult<&[u8], TrackSectorList<'_>> {
190190
let mut track_sector_pairs: Vec<TrackSectorPair> = Vec::new();
191191

192192
let (i, reserved) = le_u8(i)?;
@@ -315,7 +315,7 @@ impl<'a> FileEntry<'a> {
315315
locked: bool,
316316
filename: &str,
317317
file_length_in_sectors: u16,
318-
) -> FileEntry {
318+
) -> FileEntry<'_> {
319319
FileEntry {
320320
track_of_first_track_sector_list_sector,
321321
sector_of_first_track_sector_list_sector,
@@ -530,7 +530,7 @@ impl Display for FileEntry<'_> {
530530
}
531531

532532
/// Parse a file entry
533-
pub fn parse_file_entry(i: &[u8]) -> IResult<&[u8], FileEntry> {
533+
pub fn parse_file_entry(i: &[u8]) -> IResult<&[u8], FileEntry<'_>> {
534534
let (i, track_of_first_track_sector_list_sector) = le_u8(i)?;
535535
let (i, sector_of_first_track_sector_list_sector) = le_u8(i)?;
536536

@@ -657,7 +657,7 @@ pub fn valid_file(track_of_first_track_sector_list_sector: u8) -> bool {
657657
}
658658

659659
/// Parse an Apple ][ DOS disk catalog
660-
pub fn parse_catalog(i: &[u8]) -> IResult<&[u8], Catalog> {
660+
pub fn parse_catalog(i: &[u8]) -> IResult<&[u8], Catalog<'_>> {
661661
let (i, reserved) = le_u8(i)?;
662662
let (i, track_number_of_next_sector) = le_u8(i)?;
663663
let (i, sector_number_of_next_sector) = le_u8(i)?;
@@ -1510,8 +1510,7 @@ mod tests {
15101510
track_number: 0x11,
15111511
sector_number: 0x0B,
15121512
};
1513-
let mut tsps: TrackSectorPairs = Vec::new();
1514-
tsps.push(tsp);
1513+
let tsps: TrackSectorPairs = vec![tsp];
15151514

15161515
let tsl = TrackSectorList {
15171516
reserved: 0,
@@ -1618,9 +1617,7 @@ mod tests {
16181617
track_number: 0x11,
16191618
sector_number: 0x0C,
16201619
};
1621-
let mut tsps: TrackSectorPairs = Vec::new();
1622-
tsps.push(tsp1);
1623-
tsps.push(tsp2);
1620+
let tsps: TrackSectorPairs = vec![tsp1, tsp2];
16241621

16251622
let tsl = TrackSectorList {
16261623
reserved: 0,

src/disk_format/apple/disk.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ impl Display for VolumeTableOfContents<'_> {
160160
}
161161

162162
/// Parse a Volume Table of Contents
163-
pub fn parse_volume_table_of_contents(i: &[u8]) -> IResult<&[u8], VolumeTableOfContents> {
163+
pub fn parse_volume_table_of_contents(i: &[u8]) -> IResult<&[u8], VolumeTableOfContents<'_>> {
164164
let (i, reserved) = le_u8(i)?;
165165
let (i, track_number_of_first_catalog_sector) = le_u8(i)?;
166166
let (i, sector_number_of_first_catalog_sector) = le_u8(i)?;
@@ -431,7 +431,7 @@ impl<'a, 'b> DiskImageGuesser<'a, 'b> for AppleDiskGuess<'a> {
431431
///
432432
/// There was a design decision here to return None as opposed to an
433433
/// Unknown Apple image type. I don't know if it's the right choice.
434-
pub fn format_from_data(data: &[u8]) -> std::result::Result<Option<DiskImageGuess>, Error> {
434+
pub fn format_from_data(data: &[u8]) -> std::result::Result<Option<DiskImageGuess<'_>>, Error> {
435435
let filesize: u64 = data.len().try_into().unwrap();
436436

437437
info!("Reading magic number from file");
@@ -700,6 +700,7 @@ mod tests {
700700
let path = Path::new(&filename);
701701
let mut file = OpenOptions::new()
702702
.create(true)
703+
.truncate(true)
703704
.write(true)
704705
.open(path)
705706
.unwrap_or_else(|e| {
@@ -847,7 +848,7 @@ mod tests {
847848
data.extend(data_vtoc);
848849
data.extend(data_suffix);
849850

850-
std::fs::write(&path, &data).unwrap_or_else(|e| {
851+
std::fs::write(path, &data).unwrap_or_else(|e| {
851852
panic!("Error writing test file: {}", e);
852853
});
853854

@@ -903,7 +904,7 @@ mod tests {
903904
* saving it to version control */
904905
let path = Path::new(&filename);
905906
let data: [u8; 143360] = [0; 143360];
906-
std::fs::write(&path, data).unwrap_or_else(|e| {
907+
std::fs::write(path, data).unwrap_or_else(|e| {
907908
panic!("Error writing test file: {}", e);
908909
});
909910

src/disk_format/apple/nibble.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -648,7 +648,8 @@ mod tests {
648648
let mut data: [u8; 342] = [0; 342];
649649

650650
for i in 0..=341 {
651-
data[i] = NIBBLE_WRITE_TABLE_6_AND_2[(i % 0x40) as usize];
651+
// data[i] = NIBBLE_WRITE_TABLE_6_AND_2[(i % 0x40) as usize];
652+
data[i] = NIBBLE_WRITE_TABLE_6_AND_2[i % 0x40];
652653
}
653654

654655
let data_field = DataField {

src/disk_format/commodore/d64.rs

Lines changed: 9 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -701,7 +701,7 @@ impl DiskImageSaver for D64Disk<'_> {
701701
mod tests {
702702
use super::{
703703
bam_entry_parser, bam_entry_to_boolean_vector, bitmap_to_chars, d64_file_entry_parser,
704-
FileType,
704+
BooleanVector, FileType,
705705
};
706706
use crate::config::Configuration;
707707

@@ -721,29 +721,13 @@ mod tests {
721721
let bv = bam_entry_to_boolean_vector(&bam_entry.1);
722722

723723
assert_eq!(bv.0.len(), 21);
724-
assert_eq!(bv.0[0], true);
725-
assert_eq!(bv.0[1], true);
726-
assert_eq!(bv.0[2], true);
727-
assert_eq!(bv.0[3], false);
728-
assert_eq!(bv.0[4], true);
729-
assert_eq!(bv.0[5], false);
730-
assert_eq!(bv.0[6], true);
731-
assert_eq!(bv.0[7], true);
732-
733-
assert_eq!(bv.0[8], true);
734-
assert_eq!(bv.0[9], true);
735-
assert_eq!(bv.0[10], true);
736-
assert_eq!(bv.0[11], true);
737-
assert_eq!(bv.0[12], true);
738-
assert_eq!(bv.0[13], false);
739-
assert_eq!(bv.0[14], true);
740-
assert_eq!(bv.0[15], false);
741-
742-
assert_eq!(bv.0[16], true);
743-
assert_eq!(bv.0[17], true);
744-
assert_eq!(bv.0[18], true);
745-
assert_eq!(bv.0[19], true);
746-
assert_eq!(bv.0[20], true);
724+
assert_eq!(
725+
bv,
726+
BooleanVector(vec![
727+
true, true, true, false, true, false, true, true, true, true, true, true, true,
728+
false, true, false, true, true, true, true, true
729+
])
730+
);
747731
}
748732

749733
/// Test parsing STX boot sector checksum
@@ -787,10 +771,7 @@ mod tests {
787771
})
788772
.1;
789773

790-
assert_eq!(
791-
FileType::from(file_entry.file_type.file_type),
792-
FileType::Program
793-
);
774+
assert_eq!(file_entry.file_type.file_type, FileType::Program);
794775

795776
// assert_eq!(file_entry_program.file_type, 0x82);
796777
}

src/disk_format/image.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -556,7 +556,7 @@ pub fn format_from_filename_and_data<'a>(
556556
}
557557

558558
/// Function to collect the actual disk image data from a disk image and return
559-
/// it as an Option<Vec<u8>>
559+
/// it as an `Option<Vec<u8>>`
560560
/// It should have more tests around the different disk types
561561
pub fn disk_image_data(disk_image: &DiskImage) -> Option<Vec<u8>> {
562562
match disk_image {
@@ -601,6 +601,7 @@ mod tests {
601601
let path = Path::new(&filename);
602602
let mut file = OpenOptions::new()
603603
.create(true)
604+
.truncate(true)
604605
.write(true)
605606
.open(path)
606607
.unwrap_or_else(|e| {

src/disk_format/stx/disk.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ impl Display for STXDiskHeader<'_> {
137137

138138
/// The track or sector image data can be located in several places, depending on the
139139
/// fuzzy masks and track flags
140-
pub fn stx_disk_parser(i: &[u8]) -> IResult<&[u8], STXDisk> {
140+
pub fn stx_disk_parser(i: &[u8]) -> IResult<&[u8], STXDisk<'_>> {
141141
let (i, stx_disk_header) = stx_disk_header_parser(i)?;
142142

143143
if !stx_disk_header.check() {
@@ -159,7 +159,7 @@ pub fn stx_disk_parser(i: &[u8]) -> IResult<&[u8], STXDisk> {
159159

160160
// TODO: Verify that this is reading correctly
161161
/// Parse STX disks
162-
pub fn stx_disk_header_parser(i: &[u8]) -> IResult<&[u8], STXDiskHeader> {
162+
pub fn stx_disk_header_parser(i: &[u8]) -> IResult<&[u8], STXDiskHeader<'_>> {
163163
// will consume bytes if the input begins with "RSY" + 0
164164
// magic number
165165
let (i, disk_id) = tag("RSY\0")(i)?;

src/disk_format/stx/sector.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ impl Display for STXSyncMarker<'_> {
263263
}
264264

265265
/// Read in the four sync markers at the start of the track image data
266-
pub fn stx_sync_markers_parser(i: &[u8]) -> IResult<&[u8], STXSyncMarker> {
266+
pub fn stx_sync_markers_parser(i: &[u8]) -> IResult<&[u8], STXSyncMarker<'_>> {
267267
let (i, stx_sync_markers) = take(4_usize)(i)?;
268268

269269
Ok((
@@ -335,9 +335,11 @@ mod tests {
335335

336336
// equivalent to: for i in 0..256 { ... sector_data[i] }
337337
// for item in sector_data.iter().take(256) {
338+
// for i in 0..512 {
339+
// boot_sector[i] = (i & 0x00FF) as u8;
338340

339-
for i in 0..512 {
340-
boot_sector[i] = (i & 0x00FF) as u8;
341+
for (i, bs_byte) in boot_sector.iter_mut().enumerate() {
342+
*bs_byte = (i & 0x00FF) as u8;
341343
}
342344

343345
let words_result = parse_boot_sector_as_words(&boot_sector);
@@ -372,6 +374,6 @@ mod tests {
372374

373375
let checksum = calculate_boot_sector_sum_from_words(&boot_sector);
374376

375-
assert_eq!(checksum, true);
377+
assert!(checksum);
376378
}
377379
}

src/disk_format/stx/track.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ impl Display for STXTrack<'_> {
184184
/// TODO: Implement full parsing
185185
/// This currently doesn't parse track data, just the headers
186186
/// TODO: Simplify this parser
187-
pub fn stx_track_parser(i: &[u8]) -> IResult<&[u8], STXTrack> {
187+
pub fn stx_track_parser(i: &[u8]) -> IResult<&[u8], STXTrack<'_>> {
188188
// Record the starting position so we can figure out how much was missed
189189
let starting_position = i;
190190
let stx_track_header_result = stx_track_header_parser(i)?;
@@ -403,7 +403,7 @@ mod tests {
403403
assert_eq!(res.record_type, 0x00);
404404

405405
// Should fail because of the flags
406-
assert_eq!(false, res.check());
406+
assert!(!res.check());
407407
}
408408
Err(e) => panic!("Parsing failed on the STX disk header: {}", e),
409409
}

src/file.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ use crate::error::Error;
2121
///
2222
/// # Examples
2323
///
24+
/// ```
2425
/// // Start of setup code
2526
/// use std::path::Path;
2627
/// use std::io::{Read, Write};

0 commit comments

Comments
 (0)