From fed8da1c9078638a96ae57a9dd6edacb0a1936b3 Mon Sep 17 00:00:00 2001 From: Richard Date: Wed, 16 Feb 2022 19:20:26 -0300 Subject: Add new `System` variant to `Action` --- native/src/system/action.rs | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 native/src/system/action.rs (limited to 'native/src/system/action.rs') diff --git a/native/src/system/action.rs b/native/src/system/action.rs new file mode 100644 index 00000000..0d484957 --- /dev/null +++ b/native/src/system/action.rs @@ -0,0 +1,3 @@ +/// An operation to be performed on the system. +#[derive(Debug)] +pub enum Action {} -- cgit From 69781499cb070535bfc4e968d9ed3102ea722fb3 Mon Sep 17 00:00:00 2001 From: Richard Date: Wed, 16 Feb 2022 19:37:38 -0300 Subject: Introduce `QueryInformation` to `system::Action` --- native/src/system/action.rs | 37 +++++++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) (limited to 'native/src/system/action.rs') diff --git a/native/src/system/action.rs b/native/src/system/action.rs index 0d484957..3bece0bb 100644 --- a/native/src/system/action.rs +++ b/native/src/system/action.rs @@ -1,3 +1,36 @@ +use crate::system; + +use iced_futures::MaybeSend; + +use std::fmt; + /// An operation to be performed on the system. -#[derive(Debug)] -pub enum Action {} +pub enum Action { + /// Query system information and produce `T` with the result. + QueryInformation(Box) -> T>), +} + +impl Action { + /// Maps the output of a system [`Action`] using the provided closure. + pub fn map( + self, + f: impl Fn(T) -> A + 'static + MaybeSend + Sync, + ) -> Action + where + T: 'static, + { + match self { + Self::QueryInformation(o) => { + Action::QueryInformation(Box::new(move |s| f(o(s)))) + } + } + } +} + +impl fmt::Debug for Action { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + match self { + Self::QueryInformation(_) => write!(f, "Action::QueryInformation"), + } + } +} -- cgit From 5eefa5d4ead9ebfac7dab1db9aebf9797d2dad38 Mon Sep 17 00:00:00 2001 From: Richard Date: Wed, 27 Apr 2022 16:18:27 -0300 Subject: Simplify the `QueryInformation` Action --- native/src/system/action.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'native/src/system/action.rs') diff --git a/native/src/system/action.rs b/native/src/system/action.rs index 3bece0bb..6dab20a6 100644 --- a/native/src/system/action.rs +++ b/native/src/system/action.rs @@ -7,7 +7,7 @@ use std::fmt; /// An operation to be performed on the system. pub enum Action { /// Query system information and produce `T` with the result. - QueryInformation(Box) -> T>), + QueryInformation(Box T>), } impl Action { -- cgit From f1ec0af5070fe2752967cdc38ed66b8b70882366 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Wed, 4 May 2022 14:25:04 +0200 Subject: Run `system::information` in a different thread ... since it seems it can block for a couple of seconds. --- native/src/system/action.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'native/src/system/action.rs') diff --git a/native/src/system/action.rs b/native/src/system/action.rs index 6dab20a6..dea9536f 100644 --- a/native/src/system/action.rs +++ b/native/src/system/action.rs @@ -1,15 +1,18 @@ use crate::system; use iced_futures::MaybeSend; - use std::fmt; /// An operation to be performed on the system. pub enum Action { /// Query system information and produce `T` with the result. - QueryInformation(Box T>), + QueryInformation(Box>), } +pub trait Closure: Fn(system::Information) -> T + MaybeSend {} + +impl Closure for T where T: Fn(system::Information) -> O + MaybeSend {} + impl Action { /// Maps the output of a system [`Action`] using the provided closure. pub fn map( -- cgit