Skip to content

Commit 3520b99

Browse files
committed
chore: rust edition 2024
1 parent c9a359c commit 3520b99

File tree

5 files changed

+60
-58
lines changed

5 files changed

+60
-58
lines changed

.rustfmt.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
# https://rust-lang.github.io/rustfmt/?version=v1.6.0&search=
2-
edition = "2021"
1+
# https://rust-lang.github.io/rustfmt/
2+
edition = "2024"
33
max_width = 100
44
use_small_heuristics = "Max"
55
tab_spaces = 2

Cargo.lock

Lines changed: 15 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "macmon"
33
version = "0.5.1"
4-
edition = "2021"
4+
edition = "2024"
55

66
[lints.rust]
77
non_camel_case_types = "allow"
@@ -11,13 +11,14 @@ unreachable_code = "allow"
1111
[profile.release]
1212
panic = "abort"
1313
strip = false
14+
lto = false
1415

1516
[dependencies]
16-
clap = { version = "4.5.23", features = ["derive"] }
17+
clap = { version = "4.5.30", features = ["derive"] }
1718
core-foundation = "0.10.0"
18-
libc = "0.2.168"
19+
libc = "0.2.170"
1920
num-traits = "0.2.19"
2021
ratatui = { version = "0.29.0", features = ["serde"] }
21-
serde = { version = "1.0.216", features = ["derive"] }
22+
serde = { version = "1.0.218", features = ["derive"] }
2223
serde-inline-default = "0.2.3"
23-
serde_json = "1.0.133"
24+
serde_json = "1.0.139"

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ lint:
22
cargo fmt --check
33
cargo check --release --locked
44

5+
build:
6+
cargo build --release
7+
ls -lh target/release/$(shell basename $(CURDIR))
8+
59
update:
610
@# cargo install cargo-edit
711
cargo upgrade -i

src/sources.rs

Lines changed: 33 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,22 @@
44
use std::{
55
collections::HashMap,
66
marker::{PhantomData, PhantomPinned},
7-
mem::{size_of, MaybeUninit},
7+
mem::{MaybeUninit, size_of},
88
os::raw::c_void,
99
ptr::null,
1010
};
1111

1212
use core_foundation::{
1313
array::{CFArrayGetCount, CFArrayGetValueAtIndex, CFArrayRef},
14-
base::{kCFAllocatorDefault, kCFAllocatorNull, CFAllocatorRef, CFRange, CFRelease, CFTypeRef},
14+
base::{CFAllocatorRef, CFRange, CFRelease, CFTypeRef, kCFAllocatorDefault, kCFAllocatorNull},
1515
data::{CFDataGetBytes, CFDataGetLength, CFDataRef},
1616
dictionary::{
17-
kCFTypeDictionaryKeyCallBacks, kCFTypeDictionaryValueCallBacks, CFDictionaryCreate,
18-
CFDictionaryCreateMutableCopy, CFDictionaryGetCount, CFDictionaryGetKeysAndValues,
19-
CFDictionaryGetValue, CFDictionaryRef, CFMutableDictionaryRef,
17+
CFDictionaryCreate, CFDictionaryCreateMutableCopy, CFDictionaryGetCount,
18+
CFDictionaryGetKeysAndValues, CFDictionaryGetValue, CFDictionaryRef, CFMutableDictionaryRef,
19+
kCFTypeDictionaryKeyCallBacks, kCFTypeDictionaryValueCallBacks,
2020
},
21-
number::{kCFNumberSInt32Type, CFNumberCreate, CFNumberRef},
22-
string::{kCFStringEncodingUTF8, CFStringCreateWithBytesNoCopy, CFStringGetCString, CFStringRef},
21+
number::{CFNumberCreate, CFNumberRef, kCFNumberSInt32Type},
22+
string::{CFStringCreateWithBytesNoCopy, CFStringGetCString, CFStringRef, kCFStringEncodingUTF8},
2323
};
2424

2525
pub type WithError<T> = Result<T, Box<dyn std::error::Error>>;
@@ -88,7 +88,7 @@ pub fn cfdict_get_val(dict: CFDictionaryRef, key: &str) -> Option<CFTypeRef> {
8888

8989
#[link(name = "IOKit", kind = "framework")]
9090
#[rustfmt::skip]
91-
extern "C" {
91+
unsafe extern "C" {
9292
fn IOServiceMatching(name: *const i8) -> CFMutableDictionaryRef;
9393
fn IOServiceGetMatchingServices(mainPort: u32, matching: CFDictionaryRef, existing: *mut u32) -> i32;
9494
fn IOIteratorNext(iterator: u32) -> u32;
@@ -107,7 +107,7 @@ type IOReportSubscriptionRef = *const IOReportSubscription;
107107

108108
#[link(name = "IOReport", kind = "dylib")]
109109
#[rustfmt::skip]
110-
extern "C" {
110+
unsafe extern "C" {
111111
fn IOReportCopyAllChannels(a: u64, b: u64) -> CFDictionaryRef;
112112
fn IOReportCopyChannelsInGroup(a: CFStringRef, b: CFStringRef, c: u64, d: u64, e: u64) -> CFDictionaryRef;
113113
fn IOReportMergeChannels(a: CFDictionaryRef, b: CFDictionaryRef, nil: CFTypeRef);
@@ -251,9 +251,7 @@ impl IOReportIterator {
251251

252252
impl Drop for IOReportIterator {
253253
fn drop(&mut self) {
254-
unsafe {
255-
CFRelease(self.sample as _);
256-
}
254+
unsafe { CFRelease(self.sample as _) };
257255
}
258256
}
259257

@@ -500,38 +498,40 @@ pub fn get_soc_info() -> WithError<SocInfo> {
500498

501499
// MARK: IOReport
502500

503-
unsafe fn cfio_get_chan(items: Vec<(&str, Option<&str>)>) -> WithError<CFMutableDictionaryRef> {
501+
fn cfio_get_chan(items: Vec<(&str, Option<&str>)>) -> WithError<CFMutableDictionaryRef> {
504502
// if no items are provided, return all channels
505503
if items.len() == 0 {
506-
let c = IOReportCopyAllChannels(0, 0);
507-
let r = CFDictionaryCreateMutableCopy(kCFAllocatorDefault, CFDictionaryGetCount(c), c);
508-
CFRelease(c as _);
509-
return Ok(r);
504+
unsafe {
505+
let c = IOReportCopyAllChannels(0, 0);
506+
let r = CFDictionaryCreateMutableCopy(kCFAllocatorDefault, CFDictionaryGetCount(c), c);
507+
CFRelease(c as _);
508+
return Ok(r);
509+
}
510510
}
511511

512512
let mut channels = vec![];
513513
for (group, subgroup) in items {
514514
let gname = cfstr(group);
515515
let sname = subgroup.map_or(null(), |x| cfstr(x));
516-
let chan = IOReportCopyChannelsInGroup(gname, sname, 0, 0, 0);
516+
let chan = unsafe { IOReportCopyChannelsInGroup(gname, sname, 0, 0, 0) };
517517
channels.push(chan);
518518

519-
CFRelease(gname as _);
519+
unsafe { CFRelease(gname as _) };
520520
if subgroup.is_some() {
521-
CFRelease(sname as _);
521+
unsafe { CFRelease(sname as _) };
522522
}
523523
}
524524

525525
let chan = channels[0];
526526
for i in 1..channels.len() {
527-
IOReportMergeChannels(chan, channels[i], null());
527+
unsafe { IOReportMergeChannels(chan, channels[i], null()) };
528528
}
529529

530-
let size = CFDictionaryGetCount(chan);
531-
let chan = CFDictionaryCreateMutableCopy(kCFAllocatorDefault, size, chan);
530+
let size = unsafe { CFDictionaryGetCount(chan) };
531+
let chan = unsafe { CFDictionaryCreateMutableCopy(kCFAllocatorDefault, size, chan) };
532532

533533
for i in 0..channels.len() {
534-
CFRelease(channels[i] as _);
534+
unsafe { CFRelease(channels[i] as _) };
535535
}
536536

537537
if cfdict_get_val(chan, "IOReportChannels").is_none() {
@@ -541,14 +541,14 @@ unsafe fn cfio_get_chan(items: Vec<(&str, Option<&str>)>) -> WithError<CFMutable
541541
Ok(chan)
542542
}
543543

544-
unsafe fn cfio_get_subs(chan: CFMutableDictionaryRef) -> WithError<IOReportSubscriptionRef> {
544+
fn cfio_get_subs(chan: CFMutableDictionaryRef) -> WithError<IOReportSubscriptionRef> {
545545
let mut s: MaybeUninit<CFMutableDictionaryRef> = MaybeUninit::uninit();
546-
let rs = IOReportCreateSubscription(std::ptr::null(), chan, s.as_mut_ptr(), 0, std::ptr::null());
547-
if rs == std::ptr::null() {
546+
let rs = unsafe { IOReportCreateSubscription(null(), chan, s.as_mut_ptr(), 0, null()) };
547+
if rs.is_null() {
548548
return Err("Failed to create subscription".into());
549549
}
550550

551-
s.assume_init();
551+
unsafe { s.assume_init() };
552552
Ok(rs)
553553
}
554554

@@ -560,9 +560,8 @@ pub struct IOReport {
560560

561561
impl IOReport {
562562
pub fn new(channels: Vec<(&str, Option<&str>)>) -> WithError<Self> {
563-
let chan = unsafe { cfio_get_chan(channels)? };
564-
let subs = unsafe { cfio_get_subs(chan)? };
565-
563+
let chan = cfio_get_chan(channels)?;
564+
let subs = cfio_get_subs(chan)?;
566565
Ok(Self { subs, chan, prev: None })
567566
}
568567

@@ -647,7 +646,7 @@ const kIOHIDEventTypePower: i64 = 25;
647646

648647
#[link(name = "IOKit", kind = "framework")]
649648
#[rustfmt::skip]
650-
extern "C" {
649+
unsafe extern "C" {
651650
fn IOHIDEventSystemClientCreate(allocator: CFAllocatorRef) -> IOHIDEventSystemClientRef;
652651
fn IOHIDEventSystemClientSetMatching(a: IOHIDEventSystemClientRef, b: CFDictionaryRef) -> i32;
653652
fn IOHIDEventSystemClientCopyServices(a: IOHIDEventSystemClientRef) -> CFArrayRef;
@@ -728,16 +727,14 @@ impl IOHIDSensors {
728727

729728
impl Drop for IOHIDSensors {
730729
fn drop(&mut self) {
731-
unsafe {
732-
CFRelease(self.sensors as _);
733-
}
730+
unsafe { CFRelease(self.sensors as _) };
734731
}
735732
}
736733

737734
// MARK: SMC Bindings
738735

739736
#[link(name = "IOKit", kind = "framework")]
740-
extern "C" {
737+
unsafe extern "C" {
741738
fn mach_task_self() -> u32;
742739
fn IOServiceOpen(device: u32, a: u32, b: u32, c: *mut u32) -> i32;
743740
fn IOServiceClose(conn: u32) -> i32;

0 commit comments

Comments
 (0)