Skip to content

Commit 6e517ac

Browse files
authored
Update dependencies to allow building with latest Rust version (#31)
1 parent 34a7c63 commit 6e517ac

File tree

3 files changed

+61
-53
lines changed

3 files changed

+61
-53
lines changed

.github/workflows/rust.yml

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ env:
1313
jobs:
1414
test:
1515
strategy:
16+
fail-fast: false
1617
matrix:
1718
os:
1819
- ubuntu-latest
@@ -25,7 +26,7 @@ jobs:
2526
- os: ubuntu-latest
2627
rust: msrv
2728
lint: 1
28-
- rust: stable
29+
- rust: msrv
2930
rust-args: --all-features
3031
runs-on: ${{ matrix.os }}
3132
steps:
@@ -38,7 +39,7 @@ jobs:
3839
ver="${{ matrix.rust }}"
3940
if [ "$ver" = msrv ]; then
4041
ver=$(cargo metadata --format-version 1 --no-deps | \
41-
jq -r '.packages[0].rust_version')
42+
jq -r 'first(.packages[] | select(.rust_version != null).rust_version)')
4243
extra=(-c rustfmt -c clippy)
4344
fi
4445
rustup toolchain install "$ver" --profile minimal --no-self-update "${extra[@]}"
@@ -49,17 +50,10 @@ jobs:
4950
5051
- uses: Swatinem/rust-cache@v2
5152

52-
- name: Set serde-big-array to minimum version (0.4.1)
53-
if: matrix.rust == 'msrv'
54-
run: cargo update -p serde-big-array --precise 0.4.1
53+
- run: cargo test --workspace ${{ matrix.rust-args }}
5554

56-
- name: cargo test
57-
run: cargo test --workspace ${{ matrix.rust-args }}
58-
59-
- name: rustfmt
55+
- run: cargo fmt --all -- --check
6056
if: github.event_name == 'pull_request' && matrix.lint
61-
run: cargo fmt --all -- --check
6257

63-
- name: clippy
58+
- run: cargo clippy --all --tests --all-features -- -D warnings
6459
if: github.event_name == 'pull_request' && matrix.lint
65-
run: cargo clippy --all --tests --all-features -- -D warnings

Cargo.toml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,22 @@ name = "mbrman"
33
version = "0.5.4"
44
authors = ["Cecile Tonglet <[email protected]>"]
55
edition = "2021"
6-
rust-version = "1.56"
6+
rust-version = "1.85"
77
license = "MIT OR Apache-2.0"
88
description = "MBR Partition Management in Rust"
99
repository = "https://github.com/rust-disk-partition-management/mbrman"
1010
homepage = "https://github.com/rust-disk-partition-management/mbrman"
1111
documentation = "https://docs.rs/mbrman"
1212
readme = "README.md"
1313
keywords = ["mbr", "partition", "table", "filesystem", "disk"]
14-
categories = []
14+
categories = ["filesystem"]
1515
include = ["src/**/*.rs", "tests/fixtures/*.img", "README.md", "LICENSE.Apache-2.0", "LICENSE.MIT"]
1616

1717
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
1818

1919
[dependencies]
2020
bitvec = "1.0.1"
21-
bincode = "1.0.1"
22-
serde = { version = "1.0.116", features = ["derive"] }
23-
serde-big-array = ">= 0.4.1, < 0.6"
24-
thiserror = "1.0.24"
21+
bincode = { version = "2.0.1", features = ["serde"] }
22+
serde = { version = "1.0.210", features = ["derive"] }
23+
serde-big-array = "0.5.1"
24+
thiserror = "2.0.12"

src/lib.rs

Lines changed: 49 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,9 @@
156156
157157
#![deny(missing_docs)]
158158

159-
use bincode::{deserialize_from, serialize_into};
159+
use bincode::config::legacy;
160+
use bincode::error::{DecodeError, EncodeError};
161+
use bincode::serde::{decode_from_std_read, encode_into_std_write};
160162
use bitvec::prelude::*;
161163
use serde::de::{SeqAccess, Visitor};
162164
use serde::ser::SerializeTuple;
@@ -196,7 +198,10 @@ pub enum Error {
196198
LBAExceedsMaximumCylinders,
197199
/// Deserialization errors.
198200
#[error("deserialization failed")]
199-
Deserialize(#[from] bincode::Error),
201+
Deserialize(#[from] DecodeError),
202+
/// Serialization errors.
203+
#[error("Serialization failed")]
204+
Serialize(#[from] EncodeError),
200205
/// I/O errors.
201206
#[error("generic I/O error")]
202207
Io(#[from] std::io::Error),
@@ -377,7 +382,7 @@ impl MBR {
377382
S: Seek,
378383
{
379384
let disk_size = u32::try_from(seeker.seek(SeekFrom::End(0))? / u64::from(sector_size))
380-
.unwrap_or(u32::max_value());
385+
.unwrap_or(u32::MAX);
381386
let header = MBRHeader::new(disk_signature);
382387

383388
Ok(MBR {
@@ -402,12 +407,12 @@ impl MBR {
402407
/// let mbr = mbrman::MBR::read_from(&mut f, 512)
403408
/// .expect("could not read the partition table");
404409
/// ```
405-
pub fn read_from<R: ?Sized>(mut reader: &mut R, sector_size: u32) -> Result<MBR>
410+
pub fn read_from<R>(mut reader: &mut R, sector_size: u32) -> Result<MBR>
406411
where
407-
R: Read + Seek,
412+
R: Read + Seek + ?Sized,
408413
{
409414
let disk_size = u32::try_from(reader.seek(SeekFrom::End(0))? / u64::from(sector_size))
410-
.unwrap_or(u32::max_value());
415+
.unwrap_or(u32::MAX);
411416
let header = MBRHeader::read_from(&mut reader)?;
412417

413418
let mut logical_partitions = Vec::new();
@@ -481,13 +486,13 @@ impl MBR {
481486

482487
/// Updates the header to match the specifications of the seeker given in argument.
483488
/// `disk_size` will be updated after this operation.
484-
pub fn update_from<S: ?Sized>(&mut self, seeker: &mut S) -> Result<()>
489+
pub fn update_from<S>(&mut self, seeker: &mut S) -> Result<()>
485490
where
486-
S: Seek,
491+
S: Seek + ?Sized,
487492
{
488493
self.disk_size =
489494
u32::try_from(seeker.seek(SeekFrom::End(0))? / u64::from(self.sector_size))
490-
.unwrap_or(u32::max_value());
495+
.unwrap_or(u32::MAX);
491496
Ok(())
492497
}
493498

@@ -549,9 +554,9 @@ impl MBR {
549554
/// mbr.write_into(&mut cur)
550555
/// .expect("could not write MBR to disk")
551556
/// ```
552-
pub fn write_into<W: ?Sized>(&mut self, mut writer: &mut W) -> Result<()>
557+
pub fn write_into<W>(&mut self, mut writer: &mut W) -> Result<()>
553558
where
554-
W: Write + Seek,
559+
W: Write + Seek + ?Sized,
555560
{
556561
self.header.write_into(&mut writer)?;
557562

@@ -588,11 +593,10 @@ impl MBR {
588593
writer.seek(SeekFrom::Start(u64::from(
589594
l.absolute_ebr_lba * self.sector_size,
590595
)))?;
591-
serialize_into(&mut writer, &BootstrapCode446(l.bootstrap_code))?;
592-
serialize_into(&mut writer, &partition)?;
596+
encode_into_std_write(BootstrapCode446(l.bootstrap_code), &mut writer, legacy())?;
597+
encode_into_std_write(&partition, &mut writer, legacy())?;
593598
if let Some(next) = next {
594-
serialize_into(
595-
&mut writer,
599+
encode_into_std_write(
596600
&MBRPartitionEntry {
597601
boot: BOOT_INACTIVE,
598602
first_chs: next.ebr_first_chs,
@@ -603,12 +607,14 @@ impl MBR {
603607
.saturating_sub(extended.starting_lba),
604608
sectors: next.ebr_sectors.unwrap(),
605609
},
610+
&mut writer,
611+
legacy(),
606612
)?;
607613
} else {
608-
serialize_into(&mut writer, &MBRPartitionEntry::empty())?;
614+
encode_into_std_write(MBRPartitionEntry::empty(), &mut writer, legacy())?;
609615
}
610616
writer.write_all(&[0; 16 * 2])?;
611-
serialize_into(&mut writer, &BOOT_SIGNATURE)?;
617+
encode_into_std_write(BOOT_SIGNATURE, &mut writer, legacy())?;
612618
}
613619
}
614620

@@ -1128,12 +1134,12 @@ impl MBRHeader {
11281134

11291135
/// Attempt to read a MBR header from a reader. This operation will seek at the
11301136
/// correct location before trying to write to disk.
1131-
pub fn read_from<R: ?Sized>(mut reader: &mut R) -> Result<MBRHeader>
1137+
pub fn read_from<R>(mut reader: &mut R) -> Result<MBRHeader>
11321138
where
1133-
R: Read + Seek,
1139+
R: Read + Seek + ?Sized,
11341140
{
11351141
reader.seek(SeekFrom::Start(0))?;
1136-
let header: Self = deserialize_from(&mut reader)?;
1142+
let header: Self = decode_from_std_read(&mut reader, legacy())?;
11371143
header.check()?;
11381144
Ok(header)
11391145
}
@@ -1154,13 +1160,13 @@ impl MBRHeader {
11541160

11551161
/// Write the MBR header into a writer. This operation will seek at the
11561162
/// correct location before trying to write to disk.
1157-
pub fn write_into<W: ?Sized>(&self, mut writer: &mut W) -> Result<()>
1163+
pub fn write_into<W>(&self, mut writer: &mut W) -> Result<()>
11581164
where
1159-
W: Write + Seek,
1165+
W: Write + Seek + ?Sized,
11601166
{
11611167
self.check()?;
11621168
writer.seek(SeekFrom::Start(0))?;
1163-
serialize_into(&mut writer, &self)?;
1169+
encode_into_std_write(self, &mut writer, legacy())?;
11641170

11651171
Ok(())
11661172
}
@@ -1178,14 +1184,14 @@ impl Index<usize> for MBRHeader {
11781184
type Output = MBRPartitionEntry;
11791185

11801186
fn index(&self, i: usize) -> &Self::Output {
1181-
assert!(i != 0, "invalid partition index: 0");
1187+
assert_ne!(i, 0, "invalid partition index: 0");
11821188
self.get(i).expect("invalid partition")
11831189
}
11841190
}
11851191

11861192
impl IndexMut<usize> for MBRHeader {
11871193
fn index_mut(&mut self, i: usize) -> &mut Self::Output {
1188-
assert!(i != 0, "invalid partition index: 0");
1194+
assert_ne!(i, 0, "invalid partition index: 0");
11891195
self.get_mut(i).expect("invalid partition")
11901196
}
11911197
}
@@ -1202,11 +1208,11 @@ struct EBRHeader {
12021208
}
12031209

12041210
impl EBRHeader {
1205-
fn read_from<R: ?Sized>(reader: &mut R) -> Result<EBRHeader>
1211+
fn read_from<R>(reader: &mut R) -> Result<EBRHeader>
12061212
where
12071213
R: Read,
12081214
{
1209-
let header: Self = deserialize_from(reader)?;
1215+
let header: Self = decode_from_std_read(reader, legacy())?;
12101216
header.check()?;
12111217
Ok(header)
12121218
}
@@ -1562,6 +1568,7 @@ impl Serialize for CHS {
15621568
#[allow(clippy::cognitive_complexity)]
15631569
mod tests {
15641570
use super::*;
1571+
use bincode::serde::{decode_from_slice, encode_into_slice};
15651572
use std::fs::File;
15661573
use std::io::Cursor;
15671574

@@ -1570,7 +1577,7 @@ mod tests {
15701577

15711578
#[test]
15721579
fn deserialize_maximum_chs_value() {
1573-
let chs: CHS = bincode::deserialize(&[0xff, 0xff, 0xff]).unwrap();
1580+
let chs: CHS = decode_from_slice(&[0xff, 0xff, 0xff], legacy()).unwrap().0;
15741581
assert_eq!(
15751582
chs,
15761583
CHS {
@@ -1588,13 +1595,16 @@ mod tests {
15881595
head: 255,
15891596
sector: 63,
15901597
};
1591-
let out = bincode::serialize(&chs).unwrap();
1592-
assert_eq!(out, &[0xff, 0xff, 0xff]);
1598+
let mut slice = [0; 3];
1599+
encode_into_slice(chs, &mut slice, legacy()).unwrap();
1600+
for element in slice {
1601+
assert_eq!(element, 0xff);
1602+
}
15931603
}
15941604

15951605
#[test]
15961606
fn serialize_and_deserialize_some_chs_value() {
1597-
let chs: CHS = bincode::deserialize(&[0xaa, 0xaa, 0xaa]).unwrap();
1607+
let chs: CHS = decode_from_slice(&[0xaa, 0xaa, 0xaa], legacy()).unwrap().0;
15981608
assert_eq!(
15991609
chs,
16001610
CHS {
@@ -1603,8 +1613,11 @@ mod tests {
16031613
sector: 42,
16041614
}
16051615
);
1606-
let out = bincode::serialize(&chs).unwrap();
1607-
assert_eq!(out, &[0xaa, 0xaa, 0xaa]);
1616+
let mut slice = [0; 3];
1617+
encode_into_slice(chs, &mut slice, legacy()).unwrap();
1618+
for element in slice {
1619+
assert_eq!(element, 0xaa);
1620+
}
16081621
}
16091622

16101623
#[test]
@@ -1707,7 +1720,7 @@ mod tests {
17071720
assert_eq!(
17081721
CHS::from_lba_exact(
17091722
mbr.logical_partitions[2].partition.starting_lba,
1710-
u16::max_value(),
1723+
u16::MAX,
17111724
2,
17121725
3
17131726
)
@@ -2042,7 +2055,8 @@ mod tests {
20422055
mbr.header.partition_1.sys = 0x0f;
20432056
mbr.header.partition_1.starting_lba = 1;
20442057
mbr.header.partition_1.sectors = 10;
2045-
mbr.push(0x0f, 1, 9).unwrap().partition.boot = BOOT_ACTIVE | 0x01;
2058+
let partition = mbr.push(0x0f, 1, 9).unwrap();
2059+
partition.partition.boot = BOOT_ACTIVE | 0x01;
20462060
assert!(matches!(
20472061
mbr.write_into(&mut cur).unwrap_err(),
20482062
Error::InvalidBootFlag

0 commit comments

Comments
 (0)