From cf6171a51fd8a9e58da72afe61651caacc84e311 Mon Sep 17 00:00:00 2001 From: Dorota Czaplejewicz Date: Tue, 6 Dec 2022 13:01:25 +0000 Subject: [PATCH] loops: Use Void for infinite loops --- src/actors/external/debug.rs | 9 +++++---- src/actors/external/mod.rs | 5 ++++- src/actors/external/screensaver.rs | 5 +++-- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/actors/external/debug.rs b/src/actors/external/debug.rs index bac4fa31..253d1d0e 100644 --- a/src/actors/external/debug.rs +++ b/src/actors/external/debug.rs @@ -3,12 +3,13 @@ * * SPDX-License-Identifier: GPL-3.0-or-later */ -use std::thread; -use zbus::{Connection, ObjectServer, dbus_interface, fdo}; - use crate::main; use crate::state; +use std::thread; +use zbus::{Connection, ObjectServer, dbus_interface, fdo}; + +use super::Void; use std::convert::TryInto; @@ -37,7 +38,7 @@ impl Manager { } } -fn start(mgr: Manager) -> Result<(), Box> { +fn start(mgr: Manager) -> Result> { let connection = Connection::new_session()?; fdo::DBusProxy::new(&connection)?.request_name( "sm.puri.SqueekDebug", diff --git a/src/actors/external/mod.rs b/src/actors/external/mod.rs index 624d89da..d591386a 100644 --- a/src/actors/external/mod.rs +++ b/src/actors/external/mod.rs @@ -8,4 +8,7 @@ pub mod debug; #[cfg(feature = "zbus_v1_5")] -pub mod screensaver; \ No newline at end of file +pub mod screensaver; + +/// The uninhabited type. Cannot be created or returned; means "will never return" as return type. Useful for infinite loops. +enum Void {} \ No newline at end of file diff --git a/src/actors/external/screensaver.rs b/src/actors/external/screensaver.rs index bc496f2a..e0a5b338 100644 --- a/src/actors/external/screensaver.rs +++ b/src/actors/external/screensaver.rs @@ -3,10 +3,11 @@ * * SPDX-License-Identifier: GPL-3.0-or-later */ +use crate::logging; use std::thread; use zbus::{Connection, dbus_proxy}; -use crate::logging; +use super::Void; #[derive(Debug)] @@ -45,7 +46,7 @@ pub fn init(destination: Destination) { }); } -fn start(destination: Destination) -> Result<(), zbus::Error> { +fn start(destination: Destination) -> Result { let conn = Connection::new_session()?; let manager = ManagerProxy::new(&conn)?;