use std::borrow::Cow; use serde::Deserialize; use super::{Exec, Key}; #[derive(Clone, Debug, Deserialize)] pub struct Control { pub on: Vec, #[serde(deserialize_with = "Exec::deserialize")] pub exec: Vec, pub desc: Option, } impl Control { #[inline] pub fn to_call(&self) -> Vec { self.exec.clone() } } impl Control { #[inline] pub fn on(&self) -> String { self.on.iter().map(ToString::to_string).collect() } #[inline] pub fn exec(&self) -> String { self.exec.iter().map(|e| e.to_string()).collect::>().join("; ") } #[inline] pub fn desc_or_exec(&self) -> Cow { if let Some(ref s) = self.desc { Cow::Borrowed(s) } else { self.exec().into() } } #[inline] pub fn contains(&self, s: &str) -> bool { self.desc.as_ref().map(|d| d.contains(s)) == Some(true) || self.exec().contains(s) || self.on().contains(s) } }