Skip to content

Commit

Permalink
chore(deps): replace bit-field with bitfield-struct
Browse files Browse the repository at this point in the history
  • Loading branch information
Oakchris1955 committed Jul 26, 2024
1 parent 196aaf2 commit 7565830
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 21 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ version = "0.1.0"
edition = "2021"

[dependencies]
bit-struct = "0.3.2"
bitfield-struct = "0.8.0"
bitflags = "2.6.0"
displaydoc = { version = "0.2.5", default-features = false }
time = { version = "0.3.36", default-features = false, features = [ "alloc", "parsing", "macros" ]}
Expand Down
46 changes: 26 additions & 20 deletions src/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -342,29 +342,35 @@ bitflags! {

const START_YEAR: i32 = 1980;

bit_struct! {
struct TimeAttribute(u16) {
hour: u5,
minutes: u6,
/// Multiply by 2
seconds: u5,
}
#[bitfield(u16)]
struct TimeAttribute {
/// Multiply by 2
#[bits(5)]
seconds: u8,
#[bits(6)]
minutes: u8,
#[bits(5)]
hour: u8,
}

struct DateAttribute(u16) {
year: u7,
month: u4,
day: u5,
}
#[bitfield(u16)]
struct DateAttribute {
#[bits(5)]
day: u8,
#[bits(4)]
month: u8,
#[bits(7)]
year: u8,
}

impl TryFrom<TimeAttribute> for Time {
type Error = ();

fn try_from(mut value: TimeAttribute) -> Result<Self, Self::Error> {
fn try_from(value: TimeAttribute) -> Result<Self, Self::Error> {
time::parsing::Parsed::new()
.with_hour_24(value.hour().get().value())
.and_then(|parsed| parsed.with_minute(value.minutes().get().value()))
.and_then(|parsed| parsed.with_second(value.seconds().get().value() * 2))
.with_hour_24(value.hour())
.and_then(|parsed| parsed.with_minute(value.minutes()))
.and_then(|parsed| parsed.with_second(value.seconds() * 2))
.map(|parsed| parsed.try_into().ok())
.flatten()
.ok_or(())
Expand All @@ -374,11 +380,11 @@ impl TryFrom<TimeAttribute> for Time {
impl TryFrom<DateAttribute> for Date {
type Error = ();

fn try_from(mut value: DateAttribute) -> Result<Self, Self::Error> {
fn try_from(value: DateAttribute) -> Result<Self, Self::Error> {
time::parsing::Parsed::new()
.with_year(i32::from(value.year().get().value()) + START_YEAR)
.and_then(|parsed| parsed.with_month(value.month().get().value().try_into().ok()?))
.and_then(|parsed| parsed.with_day(num::NonZeroU8::new(value.day().get().value())?))
.with_year(i32::from(value.year()) + START_YEAR)
.and_then(|parsed| parsed.with_month(value.month().try_into().ok()?))
.and_then(|parsed| parsed.with_day(num::NonZeroU8::new(value.day())?))
.map(|parsed| parsed.try_into().ok())
.flatten()
.ok_or(())
Expand Down

0 comments on commit 7565830

Please sign in to comment.