From c73cb4c566e3f5db1c9886b016122c77cabc72f9 Mon Sep 17 00:00:00 2001 From: Simon Renblad Date: Fri, 13 Dec 2024 16:37:23 +0800 Subject: [PATCH] switch to rs-core_io --- Cargo.toml | 15 +++++------ build-nostd.sh | 2 +- src/boot_sector.rs | 2 -- src/byteorder_core_io.rs | 56 ++++++++++++++++++++-------------------- 4 files changed, 36 insertions(+), 39 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index b388308..1615fc0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -23,15 +23,14 @@ std = ["byteorder/std"] # Use dynamic allocation - required for LFN support. When used without std please enable core_io/collections alloc = [] # Default features -default = ["chrono", "std", "alloc"] +default = ["std", "alloc"] [dependencies] -byteorder = { version = "1", default-features = false } +byteorder = { version = ">=1.3, <1.5", default-features = false } bitflags = "1.0" -log = "0.4" -chrono = { version = "0.4", optional = true } -core_io = { version = "0.1", optional = true } +log = ">=0.4.14, <0.4.19" -[dev-dependencies] -env_logger = "0.5" -fscommon = "0.1" +[dependencies.core_io] +git = "https://git.m-labs.hk/srenblad/rs-core_io.git" +branch = "main" +optional = true diff --git a/build-nostd.sh b/build-nostd.sh index 3982407..9dbd382 100755 --- a/build-nostd.sh +++ b/build-nostd.sh @@ -1,4 +1,4 @@ #!/bin/sh set -e cargo build --no-default-features --features core_io -cargo build --no-default-features --features core_io,alloc,core_io/collections +cargo build --no-default-features --features core_io,alloc diff --git a/src/boot_sector.rs b/src/boot_sector.rs index 0fd80da..596ca32 100644 --- a/src/boot_sector.rs +++ b/src/boot_sector.rs @@ -851,7 +851,6 @@ mod tests { #[test] fn test_determine_sectors_per_fat() { - let _ = env_logger::try_init(); test_determine_sectors_per_fat_for_multiple_sizes(512, FatType::Fat12, 1, 2, 512); test_determine_sectors_per_fat_for_multiple_sizes(512, FatType::Fat12, 1, 1, 512); @@ -870,7 +869,6 @@ mod tests { #[test] fn test_format_boot_sector() { - let _ = env_logger::try_init(); let bytes_per_sector = 512u16; // test all partition sizes from 1MB to 2TB (u32::MAX sectors is 2TB - 1 for 512 byte sectors) let mut total_sectors_vec = Vec::new(); diff --git a/src/byteorder_core_io.rs b/src/byteorder_core_io.rs index 2609454..ae2b95d 100644 --- a/src/byteorder_core_io.rs +++ b/src/byteorder_core_io.rs @@ -48,7 +48,7 @@ pub trait ReadBytesExt: io::Read { #[inline] fn read_u8(&mut self) -> Result { let mut buf = [0; 1]; - try!(self.read_exact(&mut buf)); + self.read_exact(&mut buf)?; Ok(buf[0]) } @@ -78,7 +78,7 @@ pub trait ReadBytesExt: io::Read { #[inline] fn read_i8(&mut self) -> Result { let mut buf = [0; 1]; - try!(self.read_exact(&mut buf)); + self.read_exact(&mut buf)?; Ok(buf[0] as i8) } @@ -105,7 +105,7 @@ pub trait ReadBytesExt: io::Read { #[inline] fn read_u16(&mut self) -> Result { let mut buf = [0; 2]; - try!(self.read_exact(&mut buf)); + self.read_exact(&mut buf)?; Ok(T::read_u16(&buf)) } @@ -132,7 +132,7 @@ pub trait ReadBytesExt: io::Read { #[inline] fn read_i16(&mut self) -> Result { let mut buf = [0; 2]; - try!(self.read_exact(&mut buf)); + self.read_exact(&mut buf)?; Ok(T::read_i16(&buf)) } @@ -158,7 +158,7 @@ pub trait ReadBytesExt: io::Read { #[inline] fn read_u24(&mut self) -> Result { let mut buf = [0; 3]; - try!(self.read_exact(&mut buf)); + self.read_exact(&mut buf)?; Ok(T::read_u24(&buf)) } @@ -184,7 +184,7 @@ pub trait ReadBytesExt: io::Read { #[inline] fn read_i24(&mut self) -> Result { let mut buf = [0; 3]; - try!(self.read_exact(&mut buf)); + self.read_exact(&mut buf)?; Ok(T::read_i24(&buf)) } @@ -210,7 +210,7 @@ pub trait ReadBytesExt: io::Read { #[inline] fn read_u32(&mut self) -> Result { let mut buf = [0; 4]; - try!(self.read_exact(&mut buf)); + self.read_exact(&mut buf)?; Ok(T::read_u32(&buf)) } @@ -236,7 +236,7 @@ pub trait ReadBytesExt: io::Read { #[inline] fn read_i32(&mut self) -> Result { let mut buf = [0; 4]; - try!(self.read_exact(&mut buf)); + self.read_exact(&mut buf)?; Ok(T::read_i32(&buf)) } @@ -262,7 +262,7 @@ pub trait ReadBytesExt: io::Read { #[inline] fn read_u64(&mut self) -> Result { let mut buf = [0; 8]; - try!(self.read_exact(&mut buf)); + self.read_exact(&mut buf)?; Ok(T::read_u64(&buf)) } @@ -288,7 +288,7 @@ pub trait ReadBytesExt: io::Read { #[inline] fn read_i64(&mut self) -> Result { let mut buf = [0; 8]; - try!(self.read_exact(&mut buf)); + self.read_exact(&mut buf)?; Ok(T::read_i64(&buf)) } @@ -318,7 +318,7 @@ pub trait ReadBytesExt: io::Read { #[inline] fn read_u128(&mut self) -> Result { let mut buf = [0; 16]; - try!(self.read_exact(&mut buf)); + self.read_exact(&mut buf)?; Ok(T::read_u128(&buf)) } @@ -346,7 +346,7 @@ pub trait ReadBytesExt: io::Read { #[inline] fn read_i128(&mut self) -> Result { let mut buf = [0; 16]; - try!(self.read_exact(&mut buf)); + self.read_exact(&mut buf)?; Ok(T::read_i128(&buf)) } @@ -371,7 +371,7 @@ pub trait ReadBytesExt: io::Read { #[inline] fn read_uint(&mut self, nbytes: usize) -> Result { let mut buf = [0; 8]; - try!(self.read_exact(&mut buf[..nbytes])); + self.read_exact(&mut buf[..nbytes])?; Ok(T::read_uint(&buf[..nbytes], nbytes)) } @@ -396,7 +396,7 @@ pub trait ReadBytesExt: io::Read { #[inline] fn read_int(&mut self, nbytes: usize) -> Result { let mut buf = [0; 8]; - try!(self.read_exact(&mut buf[..nbytes])); + self.read_exact(&mut buf[..nbytes])?; Ok(T::read_int(&buf[..nbytes], nbytes)) } @@ -405,7 +405,7 @@ pub trait ReadBytesExt: io::Read { #[inline] fn read_uint128(&mut self, nbytes: usize) -> Result { let mut buf = [0; 16]; - try!(self.read_exact(&mut buf[..nbytes])); + self.read_exact(&mut buf[..nbytes])?; Ok(T::read_uint128(&buf[..nbytes], nbytes)) } @@ -414,7 +414,7 @@ pub trait ReadBytesExt: io::Read { #[inline] fn read_int128(&mut self, nbytes: usize) -> Result { let mut buf = [0; 16]; - try!(self.read_exact(&mut buf[..nbytes])); + self.read_exact(&mut buf[..nbytes])?; Ok(T::read_int128(&buf[..nbytes], nbytes)) } @@ -445,7 +445,7 @@ pub trait ReadBytesExt: io::Read { #[inline] fn read_f32(&mut self) -> Result { let mut buf = [0; 4]; - try!(self.read_exact(&mut buf)); + self.read_exact(&mut buf)?; Ok(T::read_f32(&buf)) } @@ -476,7 +476,7 @@ pub trait ReadBytesExt: io::Read { #[inline] fn read_f64(&mut self) -> Result { let mut buf = [0; 8]; - try!(self.read_exact(&mut buf)); + self.read_exact(&mut buf)?; Ok(T::read_f64(&buf)) } @@ -509,7 +509,7 @@ pub trait ReadBytesExt: io::Read { fn read_u16_into(&mut self, dst: &mut [u16]) -> Result<()> { { let buf = unsafe { slice_to_u8_mut(dst) }; - try!(self.read_exact(buf)); + self.read_exact(buf)?; } T::from_slice_u16(dst); Ok(()) @@ -544,7 +544,7 @@ pub trait ReadBytesExt: io::Read { fn read_u32_into(&mut self, dst: &mut [u32]) -> Result<()> { { let buf = unsafe { slice_to_u8_mut(dst) }; - try!(self.read_exact(buf)); + self.read_exact(buf)?; } T::from_slice_u32(dst); Ok(()) @@ -582,7 +582,7 @@ pub trait ReadBytesExt: io::Read { fn read_u64_into(&mut self, dst: &mut [u64]) -> Result<()> { { let buf = unsafe { slice_to_u8_mut(dst) }; - try!(self.read_exact(buf)); + self.read_exact(buf)?; } T::from_slice_u64(dst); Ok(()) @@ -621,7 +621,7 @@ pub trait ReadBytesExt: io::Read { fn read_u128_into(&mut self, dst: &mut [u128]) -> Result<()> { { let mut buf = unsafe { slice_to_u8_mut(dst) }; - try!(self.read_exact(buf)); + self.read_exact(buf)?; } T::from_slice_u128(dst); Ok(()) @@ -656,7 +656,7 @@ pub trait ReadBytesExt: io::Read { fn read_i16_into(&mut self, dst: &mut [i16]) -> Result<()> { { let buf = unsafe { slice_to_u8_mut(dst) }; - try!(self.read_exact(buf)); + self.read_exact(buf)?; } T::from_slice_i16(dst); Ok(()) @@ -691,7 +691,7 @@ pub trait ReadBytesExt: io::Read { fn read_i32_into(&mut self, dst: &mut [i32]) -> Result<()> { { let buf = unsafe { slice_to_u8_mut(dst) }; - try!(self.read_exact(buf)); + self.read_exact(buf)?; } T::from_slice_i32(dst); Ok(()) @@ -729,7 +729,7 @@ pub trait ReadBytesExt: io::Read { fn read_i64_into(&mut self, dst: &mut [i64]) -> Result<()> { { let buf = unsafe { slice_to_u8_mut(dst) }; - try!(self.read_exact(buf)); + self.read_exact(buf)?; } T::from_slice_i64(dst); Ok(()) @@ -768,7 +768,7 @@ pub trait ReadBytesExt: io::Read { fn read_i128_into(&mut self, dst: &mut [i128]) -> Result<()> { { let mut buf = unsafe { slice_to_u8_mut(dst) }; - try!(self.read_exact(buf)); + self.read_exact(buf)?; } T::from_slice_i128(dst); Ok(()) @@ -809,7 +809,7 @@ pub trait ReadBytesExt: io::Read { fn read_f32_into(&mut self, dst: &mut [f32]) -> Result<()> { { let buf = unsafe { slice_to_u8_mut(dst) }; - try!(self.read_exact(buf)); + self.read_exact(buf)?; } T::from_slice_f32(dst); Ok(()) @@ -891,7 +891,7 @@ pub trait ReadBytesExt: io::Read { fn read_f64_into(&mut self, dst: &mut [f64]) -> Result<()> { { let buf = unsafe { slice_to_u8_mut(dst) }; - try!(self.read_exact(buf)); + self.read_exact(buf)?; } T::from_slice_f64(dst); Ok(())