From 8b9767f6cedede2def12941ce89e14bfcd913aeb Mon Sep 17 00:00:00 2001 From: Ashley Wulber Date: Mon, 19 Feb 2024 11:28:20 -0500 Subject: [PATCH] chore: cargo fmt & geoclue docs --- geoclue2/src/lib.rs | 8 ++ timedate/examples/timedatectl.rs | 58 ++++++------ timedate/src/lib.rs | 82 ++++++++--------- upower/examples/device.rs | 26 +++--- upower/examples/on_battery.rs | 20 ++--- upower/src/device.rs | 146 +++++++++++++++---------------- upower/src/upower.rs | 50 +++++------ 7 files changed, 199 insertions(+), 191 deletions(-) diff --git a/geoclue2/src/lib.rs b/geoclue2/src/lib.rs index b218a0d..723ef12 100644 --- a/geoclue2/src/lib.rs +++ b/geoclue2/src/lib.rs @@ -53,6 +53,9 @@ trait Manager { #[dbus_proxy(object = "Client")] fn get_client(&self); + /// Use this method to explicitly destroy a client, created using GetClient() or CreateClient(). + /// + /// Long-running applications, should either use this to delete associated client(s) when not needed, or disconnect from the D-Bus connection used for communicating with Geoclue (which is implicit on client process termination). #[dbus_proxy(object = "Client")] fn delete_client<'a>(&self, client: ObjectPath<'a>); @@ -121,12 +124,17 @@ trait Client { interface = "org.freedesktop.GeoClue2.Location" )] trait Location { + /// The latitude of the location, in degrees. #[dbus_proxy(property)] fn latitude(&self) -> Result; + /// The longitude of the location, in degrees. #[dbus_proxy(property)] fn longitude(&self) -> Result; + /// The accuracy of the location fix, in meters. #[dbus_proxy(property)] fn accuracy(&self) -> Result; + /// The altitude of the location fix, in meters. + /// When unknown, its set to minimum f64 value, -1.7976931348623157e+308. #[dbus_proxy(property)] fn altitude(&self) -> Result; /// Speed in meters per second. diff --git a/timedate/examples/timedatectl.rs b/timedate/examples/timedatectl.rs index d1e1239..cfec9a0 100644 --- a/timedate/examples/timedatectl.rs +++ b/timedate/examples/timedatectl.rs @@ -9,48 +9,48 @@ const CHOICES: &[&str] = &["no", "yes"]; #[tokio::main] pub async fn main() -> zbus::Result<()> { - let connection = zbus::Connection::system().await?; - let proxy = timedate_zbus::TimeDateProxy::new(&connection).await?; + let connection = zbus::Connection::system().await?; + let proxy = timedate_zbus::TimeDateProxy::new(&connection).await?; - let ntp_service = if proxy.ntp().await? { - "active" - } else { - "inactive" - }; + let ntp_service = if proxy.ntp().await? { + "active" + } else { + "inactive" + }; - let rtc_in_local = proxy.local_rtc().await?; - let rtc_time_usecs = proxy.rtctime_usec().await?; - let time_usecs = proxy.time_usec().await?; - let timezone = proxy.timezone().await?; + let rtc_in_local = proxy.local_rtc().await?; + let rtc_time_usecs = proxy.rtctime_usec().await?; + let time_usecs = proxy.time_usec().await?; + let timezone = proxy.timezone().await?; - let tz: chrono_tz::Tz = timezone.parse().unwrap(); + let tz: chrono_tz::Tz = timezone.parse().unwrap(); - let datetime = tz.timestamp_millis_opt((time_usecs / 1000) as i64).unwrap(); + let datetime = tz.timestamp_millis_opt((time_usecs / 1000) as i64).unwrap(); - let rtc_millis = (rtc_time_usecs / 1000) as i64; - let rtc_time = (if rtc_in_local { - tz.timestamp_millis_opt(rtc_millis).unwrap() - } else { - chrono_tz::UTC.timestamp_millis_opt(rtc_millis).unwrap() - }) - .format(RTC_FORMAT); + let rtc_millis = (rtc_time_usecs / 1000) as i64; + let rtc_time = (if rtc_in_local { + tz.timestamp_millis_opt(rtc_millis).unwrap() + } else { + chrono_tz::UTC.timestamp_millis_opt(rtc_millis).unwrap() + }) + .format(RTC_FORMAT); - let local = datetime.format(TZ_FORMAT); - let universal = datetime.with_timezone(&chrono_tz::UTC).format(TZ_FORMAT); - let tz_string = datetime.format("%Z, %z"); + let local = datetime.format(TZ_FORMAT); + let universal = datetime.with_timezone(&chrono_tz::UTC).format(TZ_FORMAT); + let tz_string = datetime.format("%Z, %z"); - let rtc_in_local = CHOICES[usize::from(rtc_in_local)]; - let synchronized = CHOICES[usize::from(proxy.ntp_synchronized().await.unwrap_or_default())]; + let rtc_in_local = CHOICES[usize::from(rtc_in_local)]; + let synchronized = CHOICES[usize::from(proxy.ntp_synchronized().await.unwrap_or_default())]; - println!( - " Local time: {local} + println!( + " Local time: {local} Universal time: {universal} RTC time: {rtc_time} Time zone: {timezone} ({tz_string}) System clock synchronized: {synchronized} NTP Service: {ntp_service} RTC in local TZ: {rtc_in_local}" - ); + ); - Ok(()) + Ok(()) } diff --git a/timedate/src/lib.rs b/timedate/src/lib.rs index c6ed99d..bc8bc8b 100644 --- a/timedate/src/lib.rs +++ b/timedate/src/lib.rs @@ -18,58 +18,58 @@ use zbus::dbus_proxy; #[dbus_proxy( - interface = "org.freedesktop.timedate1", - default_service = "org.freedesktop.timedate1", - default_path = "/org/freedesktop/timedate1" + interface = "org.freedesktop.timedate1", + default_service = "org.freedesktop.timedate1", + default_path = "/org/freedesktop/timedate1" )] trait TimeDate { - /// A list of time zones known on the local system as an array of names. - fn list_timezones(&self) -> zbus::Result>; + /// A list of time zones known on the local system as an array of names. + fn list_timezones(&self) -> zbus::Result>; - /// Control whether the RTC is in local time zone or UTC. - #[dbus_proxy(name = "SetLocalRTC")] - fn set_local_rtc( - &self, - local_rtc: bool, - fix_system: bool, - interactive: bool, - ) -> zbus::Result<()>; + /// Control whether the RTC is in local time zone or UTC. + #[dbus_proxy(name = "SetLocalRTC")] + fn set_local_rtc( + &self, + local_rtc: bool, + fix_system: bool, + interactive: bool, + ) -> zbus::Result<()>; - /// Control whether the system clock is synchronized with the network using `systemd-timesyncd`. - #[dbus_proxy(name = "SetNTP")] - fn set_ntp(&self, use_ntp: bool, interactive: bool) -> zbus::Result<()>; + /// Control whether the system clock is synchronized with the network using `systemd-timesyncd`. + #[dbus_proxy(name = "SetNTP")] + fn set_ntp(&self, use_ntp: bool, interactive: bool) -> zbus::Result<()>; - /// Change the system clock. - fn set_time(&self, usec_utc: i64, relative: bool, interactive: bool) -> zbus::Result<()>; + /// Change the system clock. + fn set_time(&self, usec_utc: i64, relative: bool, interactive: bool) -> zbus::Result<()>; - /// Set the system time zone. - fn set_timezone(&self, timezone: &str, interactive: bool) -> zbus::Result<()>; + /// Set the system time zone. + fn set_timezone(&self, timezone: &str, interactive: bool) -> zbus::Result<()>; - /// Shows whether a service to perform time synchronization over network is available. - #[dbus_proxy(property, name = "CanNTP")] - fn can_ntp(&self) -> zbus::Result; + /// Shows whether a service to perform time synchronization over network is available. + #[dbus_proxy(property, name = "CanNTP")] + fn can_ntp(&self) -> zbus::Result; - /// Shows whether the RTC is configured to use UTC or the local time zone. - #[dbus_proxy(property, name = "LocalRTC")] - fn local_rtc(&self) -> zbus::Result; + /// Shows whether the RTC is configured to use UTC or the local time zone. + #[dbus_proxy(property, name = "LocalRTC")] + fn local_rtc(&self) -> zbus::Result; - /// Shows whether the NTP service is enabled. - #[dbus_proxy(property, name = "NTP")] - fn ntp(&self) -> zbus::Result; + /// Shows whether the NTP service is enabled. + #[dbus_proxy(property, name = "NTP")] + fn ntp(&self) -> zbus::Result; - /// Shows whether the kernel reports the time as synchronized. - #[dbus_proxy(property, name = "NTPSynchronized")] - fn ntp_synchronized(&self) -> zbus::Result; + /// Shows whether the kernel reports the time as synchronized. + #[dbus_proxy(property, name = "NTPSynchronized")] + fn ntp_synchronized(&self) -> zbus::Result; - /// Shows the current time in RTC. - #[dbus_proxy(property, name = "RTCTimeUSec")] - fn rtctime_usec(&self) -> zbus::Result; + /// Shows the current time in RTC. + #[dbus_proxy(property, name = "RTCTimeUSec")] + fn rtctime_usec(&self) -> zbus::Result; - /// Shows the current time. - #[dbus_proxy(property, name = "TimeUSec")] - fn time_usec(&self) -> zbus::Result; + /// Shows the current time. + #[dbus_proxy(property, name = "TimeUSec")] + fn time_usec(&self) -> zbus::Result; - /// Shows the currently-configured time zone. - #[dbus_proxy(property)] - fn timezone(&self) -> zbus::Result; + /// Shows the currently-configured time zone. + #[dbus_proxy(property)] + fn timezone(&self) -> zbus::Result; } diff --git a/upower/examples/device.rs b/upower/examples/device.rs index 2ade4bd..c26cfe6 100644 --- a/upower/examples/device.rs +++ b/upower/examples/device.rs @@ -6,21 +6,21 @@ extern crate upower_dbus; use upower_dbus::UPowerProxy; fn main() -> zbus::Result<()> { - futures::executor::block_on(async move { - let connection = zbus::Connection::system().await?; + futures::executor::block_on(async move { + let connection = zbus::Connection::system().await?; - let upower = UPowerProxy::new(&connection).await?; + let upower = UPowerProxy::new(&connection).await?; - let device = upower.get_display_device().await?; + let device = upower.get_display_device().await?; - println!("BatteryLevel: {:?}", device.battery_level().await); - println!("IconName: {:?}", device.icon_name().await); - println!("IsPresent: {:?}", device.is_present().await); - println!("Online: {:?}", device.online().await); - println!("Percentage: {:?}", device.percentage().await); - println!("State: {:?}", device.state().await); - println!("Type: {:?}", device.type_().await); + println!("BatteryLevel: {:?}", device.battery_level().await); + println!("IconName: {:?}", device.icon_name().await); + println!("IsPresent: {:?}", device.is_present().await); + println!("Online: {:?}", device.online().await); + println!("Percentage: {:?}", device.percentage().await); + println!("State: {:?}", device.state().await); + println!("Type: {:?}", device.type_().await); - Ok(()) - }) + Ok(()) + }) } diff --git a/upower/examples/on_battery.rs b/upower/examples/on_battery.rs index e920d0e..69920f6 100644 --- a/upower/examples/on_battery.rs +++ b/upower/examples/on_battery.rs @@ -7,19 +7,19 @@ use futures::stream::StreamExt; use upower_dbus::UPowerProxy; fn main() -> zbus::Result<()> { - futures::executor::block_on(async move { - let connection = zbus::Connection::system().await?; + futures::executor::block_on(async move { + let connection = zbus::Connection::system().await?; - let upower = UPowerProxy::new(&connection).await?; + let upower = UPowerProxy::new(&connection).await?; - println!("On Battery: {:?}", upower.on_battery().await); + println!("On Battery: {:?}", upower.on_battery().await); - let mut stream = upower.receive_on_battery_changed().await; + let mut stream = upower.receive_on_battery_changed().await; - while let Some(event) = stream.next().await { - eprintln!("{:?}", event.get().await); - } + while let Some(event) = stream.next().await { + eprintln!("{:?}", event.get().await); + } - Ok(()) - }) + Ok(()) + }) } diff --git a/upower/src/device.rs b/upower/src/device.rs index 7423ad1..5448d20 100644 --- a/upower/src/device.rs +++ b/upower/src/device.rs @@ -8,115 +8,115 @@ use zbus::zvariant::OwnedValue; #[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, Deserialize_repr, Serialize_repr, OwnedValue)] #[repr(u32)] pub enum BatteryState { - Unknown = 0, - Charging = 1, - Discharging = 2, - Empty = 3, - FullyCharged = 4, - PendingCharge = 5, - PendingDischarge = 6, + Unknown = 0, + Charging = 1, + Discharging = 2, + Empty = 3, + FullyCharged = 4, + PendingCharge = 5, + PendingDischarge = 6, } #[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, Deserialize_repr, Serialize_repr, OwnedValue)] #[repr(u32)] pub enum BatteryType { - Unknown = 0, - LinePower = 1, - Battery = 2, - Ups = 3, - Monitor = 4, - Mouse = 5, - Keyboard = 6, - Pda = 7, - Phone = 8, + Unknown = 0, + LinePower = 1, + Battery = 2, + Ups = 3, + Monitor = 4, + Mouse = 5, + Keyboard = 6, + Pda = 7, + Phone = 8, } #[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, Deserialize_repr, Serialize_repr, OwnedValue)] #[repr(u32)] pub enum BatteryLevel { - Unknown = 0, - None = 1, - Low = 3, - Critical = 4, - Normal = 6, - High = 7, - Full = 8, + Unknown = 0, + None = 1, + Low = 3, + Critical = 4, + Normal = 6, + High = 7, + Full = 8, } #[dbus_proxy( - interface = "org.freedesktop.UPower.Device", - default_service = "org.freedesktop.UPower", - assume_defaults = false + interface = "org.freedesktop.UPower.Device", + default_service = "org.freedesktop.UPower", + assume_defaults = false )] trait Device { - #[dbus_proxy(property)] - fn battery_level(&self) -> zbus::Result; + #[dbus_proxy(property)] + fn battery_level(&self) -> zbus::Result; - #[dbus_proxy(property)] - fn capacity(&self) -> zbus::Result; + #[dbus_proxy(property)] + fn capacity(&self) -> zbus::Result; - #[dbus_proxy(property)] - fn energy(&self) -> zbus::Result; + #[dbus_proxy(property)] + fn energy(&self) -> zbus::Result; - #[dbus_proxy(property)] - fn energy_empty(&self) -> zbus::Result; + #[dbus_proxy(property)] + fn energy_empty(&self) -> zbus::Result; - #[dbus_proxy(property)] - fn energy_full(&self) -> zbus::Result; + #[dbus_proxy(property)] + fn energy_full(&self) -> zbus::Result; - #[dbus_proxy(property)] - fn energy_full_design(&self) -> zbus::Result; + #[dbus_proxy(property)] + fn energy_full_design(&self) -> zbus::Result; - #[dbus_proxy(property)] - fn has_history(&self) -> zbus::Result; + #[dbus_proxy(property)] + fn has_history(&self) -> zbus::Result; - #[dbus_proxy(property)] - fn has_statistics(&self) -> zbus::Result; + #[dbus_proxy(property)] + fn has_statistics(&self) -> zbus::Result; - #[dbus_proxy(property)] - fn icon_name(&self) -> zbus::Result; + #[dbus_proxy(property)] + fn icon_name(&self) -> zbus::Result; - #[dbus_proxy(property)] - fn is_present(&self) -> zbus::Result; + #[dbus_proxy(property)] + fn is_present(&self) -> zbus::Result; - #[dbus_proxy(property)] - fn is_rechargeable(&self) -> zbus::Result; + #[dbus_proxy(property)] + fn is_rechargeable(&self) -> zbus::Result; - #[dbus_proxy(property)] - fn luminosity(&self) -> zbus::Result; + #[dbus_proxy(property)] + fn luminosity(&self) -> zbus::Result; - #[dbus_proxy(property)] - fn model(&self) -> zbus::Result; + #[dbus_proxy(property)] + fn model(&self) -> zbus::Result; - #[dbus_proxy(property)] - fn native_path(&self) -> zbus::Result; + #[dbus_proxy(property)] + fn native_path(&self) -> zbus::Result; - #[dbus_proxy(property)] - fn online(&self) -> zbus::Result; + #[dbus_proxy(property)] + fn online(&self) -> zbus::Result; - #[dbus_proxy(property)] - fn percentage(&self) -> zbus::Result; + #[dbus_proxy(property)] + fn percentage(&self) -> zbus::Result; - #[dbus_proxy(property)] - fn power_supply(&self) -> zbus::Result; + #[dbus_proxy(property)] + fn power_supply(&self) -> zbus::Result; - fn refresh(&self) -> zbus::Result<()>; + fn refresh(&self) -> zbus::Result<()>; - #[dbus_proxy(property)] - fn serial(&self) -> zbus::Result; + #[dbus_proxy(property)] + fn serial(&self) -> zbus::Result; - #[dbus_proxy(property)] - fn state(&self) -> zbus::Result; + #[dbus_proxy(property)] + fn state(&self) -> zbus::Result; - #[dbus_proxy(property)] - fn temperature(&self) -> zbus::Result; + #[dbus_proxy(property)] + fn temperature(&self) -> zbus::Result; - #[dbus_proxy(property, name = "Type")] - fn type_(&self) -> zbus::Result; + #[dbus_proxy(property, name = "Type")] + fn type_(&self) -> zbus::Result; - #[dbus_proxy(property)] - fn vendor(&self) -> zbus::Result; + #[dbus_proxy(property)] + fn vendor(&self) -> zbus::Result; - #[dbus_proxy(property)] - fn voltage(&self) -> zbus::Result; + #[dbus_proxy(property)] + fn voltage(&self) -> zbus::Result; } diff --git a/upower/src/upower.rs b/upower/src/upower.rs index ed7ccf5..1bfe4ab 100644 --- a/upower/src/upower.rs +++ b/upower/src/upower.rs @@ -7,37 +7,37 @@ use crate::device::{DeviceProxy, DeviceProxyBlocking}; #[dbus_proxy(interface = "org.freedesktop.UPower", assume_defaults = true)] trait UPower { - /// EnumerateDevices method - fn enumerate_devices(&self) -> zbus::Result>; + /// EnumerateDevices method + fn enumerate_devices(&self) -> zbus::Result>; - /// GetCriticalAction method - fn get_critical_action(&self) -> zbus::Result; + /// GetCriticalAction method + fn get_critical_action(&self) -> zbus::Result; - /// GetDisplayDevice method - #[dbus_proxy(object = "Device")] - fn get_display_device(&self); + /// GetDisplayDevice method + #[dbus_proxy(object = "Device")] + fn get_display_device(&self); - /// DeviceAdded signal - #[dbus_proxy(signal)] - fn device_added(&self, device: zbus::zvariant::ObjectPath<'_>) -> zbus::Result<()>; + /// DeviceAdded signal + #[dbus_proxy(signal)] + fn device_added(&self, device: zbus::zvariant::ObjectPath<'_>) -> zbus::Result<()>; - /// DeviceRemoved signal - #[dbus_proxy(signal)] - fn device_removed(&self, device: zbus::zvariant::ObjectPath<'_>) -> zbus::Result<()>; + /// DeviceRemoved signal + #[dbus_proxy(signal)] + fn device_removed(&self, device: zbus::zvariant::ObjectPath<'_>) -> zbus::Result<()>; - /// DaemonVersion property - #[dbus_proxy(property)] - fn daemon_version(&self) -> zbus::Result; + /// DaemonVersion property + #[dbus_proxy(property)] + fn daemon_version(&self) -> zbus::Result; - /// LidIsClosed property - #[dbus_proxy(property)] - fn lid_is_closed(&self) -> zbus::Result; + /// LidIsClosed property + #[dbus_proxy(property)] + fn lid_is_closed(&self) -> zbus::Result; - /// LidIsPresent property - #[dbus_proxy(property)] - fn lid_is_present(&self) -> zbus::Result; + /// LidIsPresent property + #[dbus_proxy(property)] + fn lid_is_present(&self) -> zbus::Result; - /// OnBattery property - #[dbus_proxy(property)] - fn on_battery(&self) -> zbus::Result; + /// OnBattery property + #[dbus_proxy(property)] + fn on_battery(&self) -> zbus::Result; }