Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
110 changes: 101 additions & 9 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,111 @@
name: ci

on:
pull_request:
push:
branches:
- master
- master
pull_request:

# Cancel redundant workflows on the same branch/PR
concurrency:
group: ci-${{ github.ref }}
cancel-in-progress: true

jobs:
msrv:
name: msrv
fmt:
name: Rustfmt
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: dtolnay/rust-toolchain@master

- name: Install toolchain (stable) + rustfmt
uses: dtolnay/rust-toolchain@stable
with:
toolchain: 1.70.0
components: rustfmt
- run: cargo fmt --check
- run: cargo check --all-features
- run: cargo test --all-features

- uses: Swatinem/rust-cache@v2

- name: Check formatting
run: cargo fmt --all -- --check

clippy:
name: Clippy
needs: fmt
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Install toolchain (stable) + clippy
uses: dtolnay/rust-toolchain@stable
with:
components: clippy

- uses: Swatinem/rust-cache@v2

- name: Run clippy
run: cargo clippy --all-features -- -D warnings

build:
name: Build (${{ matrix.build_type }})
needs: clippy
runs-on: ubuntu-latest
strategy:
matrix:
include:
- build_type: debug
cargo_profile: dev
- build_type: release
cargo_profile: release
steps:
- uses: actions/checkout@v3

- name: Install toolchain (stable)
uses: dtolnay/rust-toolchain@stable

- uses: Swatinem/rust-cache@v2

- name: cargo build
run: cargo build --profile ${{ matrix.cargo_profile }} --all-features

test:
name: Test
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Install toolchain (stable)
uses: dtolnay/rust-toolchain@stable

- uses: Swatinem/rust-cache@v2

- name: Run tests
run: cargo test --all-features

msrv:
name: MSRV (${{ matrix.build_type }})
needs: build
runs-on: ubuntu-latest
env:
MSRV: "1.70.0" # if you change it, remember to change it also in Cargo.toml
strategy:
matrix:
include:
- build_type: debug
cargo_profile: dev
- build_type: release
cargo_profile: release
steps:
- uses: actions/checkout@v3

- name: Install toolchain (MSRV)
uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ env.MSRV }}

- uses: Swatinem/rust-cache@v2
with:
shared-key: "rust-msrv"

- name: cargo build
run: cargo build --profile ${{ matrix.cargo_profile }} --all-features
4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ description = "Decode SMBIOS/DMI information into accessible data structures"
documentation = "https://docs.rs/dmidecode/"
repository = "https://github.com/jcreekmore/dmidecode"
license = "MIT"
rust-version = "1.70"
edition = "2021"

# if you change it, remember to change it also in ci msrv workflow
rust-version = "1.70"

[dependencies]
bitflags = { version = "2.9.1", default-features = false }
uuid = { version = "1.17.0", default-features = false }
Expand Down
22 changes: 11 additions & 11 deletions src/bitfield.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,13 +142,13 @@ impl fmt::Display for Flag<'_> {
match self.type_ {
FlagType::Significant(meaning, description) => {
if f.alternate() {
write!(f, "{}", description)
write!(f, "{description}")
} else {
write!(f, "{}", meaning)
write!(f, "{meaning}")
}
}
FlagType::Reserved(note) => {
write!(f, "{}", note)
write!(f, "{note}")
}
FlagType::Unknown => {
write!(f, "Unknown")
Expand Down Expand Up @@ -385,7 +385,7 @@ mod tests {
(7, true, LAYOUT[7]),
];
for i in iter {
println!("{:?}", i);
println!("{i:?}");
}
assert_eq!(8, iter.count(), "BYTE setted flags count");
assert_eq!(
Expand All @@ -400,10 +400,10 @@ mod tests {
let iter = Significants::new(Iter::new(0b1010_1001u8, LAYOUT));
let meanings = vec!["A", "C", "E"];
let descriptions = vec!["A Long", "C Long", "E Long"];
assert_eq!(meanings, iter.map(|v| format!("{}", v)).collect::<Vec<_>>(), "Meanings");
assert_eq!(meanings, iter.map(|v| format!("{v}")).collect::<Vec<_>>(), "Meanings");
assert_eq!(
descriptions,
iter.map(|v| format!("{:#}", v)).collect::<Vec<_>>(),
iter.map(|v| format!("{v:#}")).collect::<Vec<_>>(),
"Descriptions"
);
}
Expand Down Expand Up @@ -478,34 +478,34 @@ mod tests {
.take_while(|&&p| p < 8)
.map(|&p| Position(p))
.collect();
assert_eq!(a, b, "u8:\n{:08b}\n{:08b}", a, b);
assert_eq!(a, b, "u8:\n{a:08b}\n{b:08b}");
let a = 0b0010_1000_1010_1100u16;
let b = INDEX_SAMPLE
.iter()
.take_while(|&&p| p < 16)
.map(|&p| Position(p))
.collect();
assert_eq!(a, b, "u16:\n{:016b}\n{:016b}", a, b);
assert_eq!(a, b, "u16:\n{a:016b}\n{b:016b}");
let a = 2693408940u32;
let b = INDEX_SAMPLE
.iter()
.take_while(|&&p| p < 32)
.map(|&p| Position(p))
.collect();
assert_eq!(a, b, "u32:\n{:032b}\n{:032b}", a, b);
assert_eq!(a, b, "u32:\n{a:032b}\n{b:032b}");
let a = 2891462833508853932u64;
let b = INDEX_SAMPLE
.iter()
.take_while(|&&p| p < 64)
.map(|&p| Position(p))
.collect();
assert_eq!(a, b, "u64:\n{:064b}\n{:064b}", a, b);
assert_eq!(a, b, "u64:\n{a:064b}\n{b:064b}");
let a = 170152392186162032610075049835446806700u128;
let b = INDEX_SAMPLE
.iter()
.take_while(|&&p| p < 128)
.map(|&p| Position(p))
.collect();
assert_eq!(a, b, "u128:\n{:0128b}\n{:0128b}", a, b);
assert_eq!(a, b, "u128:\n{a:0128b}\n{b:0128b}");
}
}
27 changes: 12 additions & 15 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -320,13 +320,13 @@ impl fmt::Display for InvalidEntryPointError {
match self {
InvalidEntryPointError::NotFound => write!(f, "Input did not contain a valid SMBIOS entry point"),
InvalidEntryPointError::TooOldVersion(version) => {
write!(f, "Input version number was below 2.0: {}", version)
write!(f, "Input version number was below 2.0: {version}")
}
InvalidEntryPointError::BadSize(size) => {
write!(f, "Input contained an invalid-sized SMBIOS entry: {}", size)
write!(f, "Input contained an invalid-sized SMBIOS entry: {size}")
}
InvalidEntryPointError::BadChecksum(checksum) => {
write!(f, "SMBIOS entry point has an invalid checksum: {}", checksum)
write!(f, "SMBIOS entry point has an invalid checksum: {checksum}")
}
}
}
Expand Down Expand Up @@ -410,28 +410,25 @@ impl fmt::Display for MalformedStructureError {
MalformedStructureError::BadSize(offset, length) => {
write!(
f,
"Structure at offset {} with length {} extends beyond SMBIOS",
offset, length
"Structure at offset {offset} with length {length} extends beyond SMBIOS"
)
}
MalformedStructureError::UnterminatedStrings(offset) => {
write!(f, "Structure at offset {} with unterminated strings", offset)
write!(f, "Structure at offset {offset} with unterminated strings")
}
MalformedStructureError::InvalidStringIndex(info_type, handle, index) => {
write!(
f,
"Structure {:?} with handle {} has invalid string index {}",
info_type, handle, index
"Structure {info_type:?} with handle {handle} has invalid string index {index}"
)
}
MalformedStructureError::InvalidSlice(cause) => {
write!(f, "{}", cause)
write!(f, "{cause}")
}
MalformedStructureError::InvalidFormattedSectionLength(info_type, handle, spec, length) => {
write!(
f,
"Formatted section length of structure {:?} with handle {} should be {}{} bytes",
info_type, handle, spec, length
"Formatted section length of structure {info_type:?} with handle {handle} should be {spec}{length} bytes"
)
}
}
Expand Down Expand Up @@ -794,7 +791,7 @@ impl fmt::Display for InfoType {
//InfoType:: => write!(f, "Processor Additional Information"),
//InfoType:: => write!(f, "Inactive"),
InfoType::End => write!(f, "End-of-Table"),
InfoType::Oem(t) => write!(f, "OEM: {}", t),
InfoType::Oem(t) => write!(f, "OEM: {t}"),
}
}
}
Expand Down Expand Up @@ -849,23 +846,23 @@ mod tests {
.structures(&DMIDECODE_BIN[(entry_point.smbios_address() as usize)..])
.filter_map(|s| s.ok())
{
println!("{:?}", s);
println!("{s:?}");
}
}

#[test]
fn iterator_through_structures_v3_short() {
let entry_point = EntryPoint::search(ENTRY_V3_SHORT).unwrap();
for s in entry_point.structures(DMI_V3_SHORT).filter_map(|s| s.ok()) {
println!("{:?}", s);
println!("{s:?}");
}
}

#[test]
fn iterator_through_structures_v3() {
let entry_point = EntryPoint::search(ENTRY_V3_BIN).unwrap();
for s in entry_point.structures(DMI_V3_BIN).filter_map(|s| s.ok()) {
println!("{:?}", s);
println!("{s:?}");
}
}

Expand Down
14 changes: 7 additions & 7 deletions src/structures/000_bios.rs
Original file line number Diff line number Diff line change
Expand Up @@ -383,13 +383,13 @@ mod tests {
let sample = vec!["ISA is supported", "EISA is supported"];
let qword = 0b0101_0000;
let iter = Characteristics(qword).significants();
let result = iter.map(|f| format!("{}", f)).collect::<Vec<_>>();
let result = iter.map(|f| format!("{f}")).collect::<Vec<_>>();
assert_eq!(
sample, result,
"Significant values, default formatting ({:064b})",
qword
);
let result = iter.map(|f| format!("{:#}", f)).collect::<Vec<_>>();
let result = iter.map(|f| format!("{f:#}")).collect::<Vec<_>>();
assert_eq!(
sample, result,
"Significant values, alternative formatting ({:064b})",
Expand Down Expand Up @@ -420,13 +420,13 @@ mod tests {
let alt_sample = vec!["ACPI is supported", "1394 boot is supported"];
let byte = 0b0100_0001;
let iter = CharacteristicsExtension1(byte).significants();
let dflt_result = iter.map(|f| format!("{}", f)).collect::<Vec<_>>();
let dflt_result = iter.map(|f| format!("{f}")).collect::<Vec<_>>();
assert_eq!(
dflt_sample, dflt_result,
"Significant values, default formatting ({:08b})",
byte
);
let alt_result = iter.map(|f| format!("{:#}", f)).collect::<Vec<_>>();
let alt_result = iter.map(|f| format!("{f:#}")).collect::<Vec<_>>();
assert_eq!(
alt_sample, alt_result,
"Significant values, alternative formatting ({:08b})",
Expand All @@ -450,13 +450,13 @@ mod tests {
let long_sample = vec!["UEFI is supported","SMBIOS table describes a virtual machine. (If this bit is not set, no inference can be made about the virtuality of the system.)"];
let byte = 0b0001_1000;
let iter = CharacteristicsExtension2(byte).significants();
let result = iter.map(|f| format!("{}", f)).collect::<Vec<_>>();
let result = iter.map(|f| format!("{f}")).collect::<Vec<_>>();
assert_eq!(
short_sample, result,
"Significant values, default formatting ({:08b})",
byte
);
let result = iter.map(|f| format!("{:#}", f)).collect::<Vec<_>>();
let result = iter.map(|f| format!("{f:#}")).collect::<Vec<_>>();
assert_eq!(
long_sample, result,
"Significant values, alternative formatting ({:08b})",
Expand Down Expand Up @@ -596,7 +596,7 @@ mod tests {
.significants()
.chain(bios_result.bios_characteristics_exttension_1.unwrap().significants())
.chain(bios_result.bios_characteristics_exttension_2.unwrap().significants())
.map(|v| format!("{}", v))
.map(|v| format!("{v}"))
.collect::<Vec<_>>();
assert_eq!(
all_characteristics_sample, all_char_result,
Expand Down
2 changes: 1 addition & 1 deletion src/structures/002_baseboard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ impl fmt::Display for BoardType {
BoardType::ProcessorMemoryModule => write!(f, "Processor/Memory Module"),
BoardType::ProcessorIoModule => write!(f, "Processor/IO Module"),
BoardType::InterconnectBoard => write!(f, "Interconnect board"),
BoardType::Undefined(t) => write!(f, "Undefined: {}", t),
BoardType::Undefined(t) => write!(f, "Undefined: {t}"),
}
}
}
Expand Down
Loading
Loading