Skip to content

Commit cae9888

Browse files
committed
refactor(darwin): Use c"…" string literals in src/macos.rs
rust-lang/rfcs#3348 rust-lang/rust#105723 rust-lang/rust#117472
1 parent b6079ae commit cae9888

File tree

1 file changed

+16
-19
lines changed

1 file changed

+16
-19
lines changed

crates/slacc-system-metrics/src/macos.rs

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -22,25 +22,22 @@ use crate::{ErrnoExt, SlaccStatsError};
2222
#[rustfmt::skip]
2323
#[allow(non_upper_case_globals, dead_code)]
2424
mod constants {
25-
const fn create_cstring(input: &[u8]) -> &std::ffi::CStr {
26-
unsafe { std::ffi::CStr::from_bytes_with_nul_unchecked(input) }
27-
}
28-
pub(crate) const kIOMediaClass: &std::ffi::CStr = create_cstring(b"IOMedia\0");
29-
pub(crate) const kIOServicePlane: &std::ffi::CStr = create_cstring(b"IOService\0");
30-
pub(crate) const kIOBlockStorageDriverClass: &std::ffi::CStr = create_cstring(b"IOBlockStorageDriver\0");
31-
pub(crate) const kIOBlockStorageDriverStatisticsKey: &std::ffi::CStr = create_cstring(b"Statistics\0");
32-
pub(crate) const kIOBlockStorageDriverStatisticsBytesReadKey: &std::ffi::CStr = create_cstring(b"Bytes (Read)\0");
33-
pub(crate) const kIOBlockStorageDriverStatisticsBytesWrittenKey: &std::ffi::CStr = create_cstring(b"Bytes (Write)\0");
34-
pub(crate) const kIOBlockStorageDriverStatisticsReadErrorsKey: &std::ffi::CStr = create_cstring(b"Errors (Read)\0");
35-
pub(crate) const kIOBlockStorageDriverStatisticsWriteErrorsKey: &std::ffi::CStr = create_cstring(b"Errors (Write)\0");
36-
pub(crate) const kIOBlockStorageDriverStatisticsLatentReadTimeKey: &std::ffi::CStr = create_cstring(b"Latency Time (Read)\0");
37-
pub(crate) const kIOBlockStorageDriverStatisticsLatentWriteTimeKey: &std::ffi::CStr = create_cstring(b"Latency Time (Write)\0");
38-
pub(crate) const kIOBlockStorageDriverStatisticsReadsKey: &std::ffi::CStr = create_cstring(b"Operations (Read)\0");
39-
pub(crate) const kIOBlockStorageDriverStatisticsWritesKey: &std::ffi::CStr = create_cstring(b"Operations (Write)\0");
40-
pub(crate) const kIOBlockStorageDriverStatisticsReadRetriesKey: &std::ffi::CStr = create_cstring(b"Retries (Read)\0");
41-
pub(crate) const kIOBlockStorageDriverStatisticsWriteRetriesKey: &std::ffi::CStr = create_cstring(b"Retries (Write)\0");
42-
pub(crate) const kIOBlockStorageDriverStatisticsTotalReadTimeKey: &std::ffi::CStr = create_cstring(b"Total Time (Read)\0");
43-
pub(crate) const kIOBlockStorageDriverStatisticsTotalWriteTimeKey: &std::ffi::CStr = create_cstring(b"Total Time (Write)\0");
25+
pub(crate) const kIOMediaClass: &std::ffi::CStr = c"IOMedia";
26+
pub(crate) const kIOServicePlane: &std::ffi::CStr = c"IOService";
27+
pub(crate) const kIOBlockStorageDriverClass: &std::ffi::CStr = c"IOBlockStorageDriver";
28+
pub(crate) const kIOBlockStorageDriverStatisticsKey: &std::ffi::CStr = c"Statistics";
29+
pub(crate) const kIOBlockStorageDriverStatisticsBytesReadKey: &std::ffi::CStr = c"Bytes (Read)";
30+
pub(crate) const kIOBlockStorageDriverStatisticsBytesWrittenKey: &std::ffi::CStr = c"Bytes (Write)";
31+
pub(crate) const kIOBlockStorageDriverStatisticsReadErrorsKey: &std::ffi::CStr = c"Errors (Read)";
32+
pub(crate) const kIOBlockStorageDriverStatisticsWriteErrorsKey: &std::ffi::CStr = c"Errors (Write)";
33+
pub(crate) const kIOBlockStorageDriverStatisticsLatentReadTimeKey: &std::ffi::CStr = c"Latency Time (Read)";
34+
pub(crate) const kIOBlockStorageDriverStatisticsLatentWriteTimeKey: &std::ffi::CStr = c"Latency Time (Write)";
35+
pub(crate) const kIOBlockStorageDriverStatisticsReadsKey: &std::ffi::CStr = c"Operations (Read)";
36+
pub(crate) const kIOBlockStorageDriverStatisticsWritesKey: &std::ffi::CStr = c"Operations (Write)";
37+
pub(crate) const kIOBlockStorageDriverStatisticsReadRetriesKey: &std::ffi::CStr = c"Retries (Read)";
38+
pub(crate) const kIOBlockStorageDriverStatisticsWriteRetriesKey: &std::ffi::CStr = c"Retries (Write)";
39+
pub(crate) const kIOBlockStorageDriverStatisticsTotalReadTimeKey: &std::ffi::CStr = c"Total Time (Read)";
40+
pub(crate) const kIOBlockStorageDriverStatisticsTotalWriteTimeKey: &std::ffi::CStr = c"Total Time (Write)";
4441
}
4542

4643
#[link(name = "IOKit", kind = "framework")]

0 commit comments

Comments
 (0)