summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMaxVerevkin <maxxverrr@gmail.com>2025-04-06 17:35:16 +0300
committerMaxVerevkin <maxxverrr@gmail.com>2025-04-06 17:35:16 +0300
commit1db06d90067ad8ce1e6e5a808acddd16aac3adec (patch)
treeabd85fcc17386d12ca67ea5408c1139fcaef4ee1 /src
parent77ba6b79be0c14483eac5ea683ab1b5dcf581058 (diff)
downloadi3bar-mango-1db06d90067ad8ce1e6e5a808acddd16aac3adec.tar.gz
use dyn trait upcasting
Diffstat (limited to 'src')
-rw-r--r--src/shared_state.rs12
-rw-r--r--src/wm_info_provider.rs5
-rw-r--r--src/wm_info_provider/dummy.rs6
-rw-r--r--src/wm_info_provider/hyprland.rs4
-rw-r--r--src/wm_info_provider/niri.rs4
-rw-r--r--src/wm_info_provider/river.rs4
6 files changed, 11 insertions, 24 deletions
diff --git a/src/shared_state.rs b/src/shared_state.rs
index f2b8144..169107b 100644
--- a/src/shared_state.rs
+++ b/src/shared_state.rs
@@ -1,3 +1,5 @@
+use std::any::Any;
+
use crate::{
blocks_cache::BlocksCache,
config::Config,
@@ -16,15 +18,19 @@ pub struct SharedState {
}
impl SharedState {
+ fn downcast_provider<T: Any>(&mut self) -> Option<&mut T> {
+ <dyn Any>::downcast_mut(self.wm_info_provider.as_mut())
+ }
+
pub fn get_river(&mut self) -> Option<&mut wm_info_provider::RiverInfoProvider> {
- self.wm_info_provider.as_any().downcast_mut()
+ self.downcast_provider()
}
pub fn get_hyprland(&mut self) -> Option<&mut wm_info_provider::HyprlandInfoProvider> {
- self.wm_info_provider.as_any().downcast_mut()
+ self.downcast_provider()
}
pub fn get_niri(&mut self) -> Option<&mut wm_info_provider::NiriInfoProvider> {
- self.wm_info_provider.as_any().downcast_mut()
+ self.downcast_provider()
}
}
diff --git a/src/wm_info_provider.rs b/src/wm_info_provider.rs
index 0e3252c..4c5e904 100644
--- a/src/wm_info_provider.rs
+++ b/src/wm_info_provider.rs
@@ -21,7 +21,7 @@ pub use hyprland::*;
mod niri;
pub use niri::*;
-pub trait WmInfoProvider {
+pub trait WmInfoProvider: Any {
fn register(&self, _: &mut EventLoop) {}
fn new_ouput(&mut self, _: &mut Connection<State>, _: &Output) {}
@@ -46,9 +46,6 @@ pub trait WmInfoProvider {
_btn: PointerBtn,
) {
}
-
- // TODO: remove once RFC3324 (dyn upcasting coercion) is stabilized (hopefully in Rust 1.86.0)
- fn as_any(&mut self) -> &mut dyn Any;
}
pub fn bind(conn: &mut Connection<State>, config: &WmConfig) -> Box<dyn WmInfoProvider> {
diff --git a/src/wm_info_provider/dummy.rs b/src/wm_info_provider/dummy.rs
index 72903c7..9b1ad9a 100644
--- a/src/wm_info_provider/dummy.rs
+++ b/src/wm_info_provider/dummy.rs
@@ -2,8 +2,4 @@ use super::*;
pub struct DummyInfoProvider;
-impl WmInfoProvider for DummyInfoProvider {
- fn as_any(&mut self) -> &mut dyn Any {
- self
- }
-}
+impl WmInfoProvider for DummyInfoProvider {}
diff --git a/src/wm_info_provider/hyprland.rs b/src/wm_info_provider/hyprland.rs
index 6deeec1..52fd4eb 100644
--- a/src/wm_info_provider/hyprland.rs
+++ b/src/wm_info_provider/hyprland.rs
@@ -104,10 +104,6 @@ impl WmInfoProvider for HyprlandInfoProvider {
_ => (),
}
}
-
- fn as_any(&mut self) -> &mut dyn Any {
- self
- }
}
fn hyprland_cb(conn: &mut Connection<State>, state: &mut State) -> io::Result<()> {
diff --git a/src/wm_info_provider/niri.rs b/src/wm_info_provider/niri.rs
index 9f37c3b..48addeb 100644
--- a/src/wm_info_provider/niri.rs
+++ b/src/wm_info_provider/niri.rs
@@ -114,10 +114,6 @@ impl WmInfoProvider for NiriInfoProvider {
_ => (),
}
}
-
- fn as_any(&mut self) -> &mut dyn Any {
- self
- }
}
fn niri_cb(conn: &mut Connection<State>, state: &mut State) -> io::Result<()> {
diff --git a/src/wm_info_provider/river.rs b/src/wm_info_provider/river.rs
index 9af3385..c0321ee 100644
--- a/src/wm_info_provider/river.rs
+++ b/src/wm_info_provider/river.rs
@@ -144,10 +144,6 @@ impl WmInfoProvider for RiverInfoProvider {
_ => (),
}
}
-
- fn as_any(&mut self) -> &mut dyn Any {
- self
- }
}
fn output_status_cb(ctx: EventCtx<State, ZriverOutputStatusV1>) {