about summary refs log tree commit diff
path: root/src/module.rs
blob: a716fa7aca7098018af923214d15e84313d76f11 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
use crate::error::Result;
use crate::facility::{ FacilityMap, FacilityType };

use std::time::Duration;

use async_executor::StaticExecutor;


pub use battery::BatteryModule;
pub use i3_mode::I3ModeModule;
pub use time::TimeModule;

pub mod battery;
pub mod i3_mode;
pub mod time;


/*   As with Facility, we need a separate trait for the stuff that wouldn't be
 * dyn-compatible.
 */
pub trait CreatableModule: Module + Sized {
  const REQUIRED_FACILITIES: FacilityType;

  async fn new(facilities: &mut FacilityMap, executor: &'static StaticExecutor)
      -> Result<Self>;

  /* The only way to coerce to dyn is to return as it! */
  fn as_box<'a>(self) -> Box<dyn Module + 'a>
    where Self: 'a
  {
    Box::new(self)
  }
}

pub trait Module {
  fn format(&mut self, facilities: &mut FacilityMap) -> Result<String>;
  fn sleep_duration(&self) -> Option<Duration>;
  fn is_visible(&self) -> bool;
}