layer_shika_domain/value_objects/
output_policy.rs1use crate::value_objects::output_info::OutputInfo;
2use std::fmt;
3use std::rc::Rc;
4
5type OutputFilter = Rc<dyn Fn(&OutputInfo) -> bool>;
6
7#[derive(Clone, Default)]
9pub enum OutputPolicy {
10 #[default]
12 AllOutputs,
13 PrimaryOnly,
15 Custom(OutputFilter),
17}
18
19impl OutputPolicy {
20 pub fn should_render(&self, info: &OutputInfo) -> bool {
21 match self {
22 OutputPolicy::AllOutputs => true,
23 OutputPolicy::PrimaryOnly => info.is_primary(),
24 OutputPolicy::Custom(filter) => filter(info),
25 }
26 }
27
28 pub fn primary_only() -> Self {
29 Self::PrimaryOnly
30 }
31
32 pub fn all_outputs() -> Self {
33 Self::AllOutputs
34 }
35
36 pub fn custom<F>(filter: F) -> Self
37 where
38 F: Fn(&OutputInfo) -> bool + 'static,
39 {
40 Self::Custom(Rc::new(filter))
41 }
42}
43
44impl fmt::Debug for OutputPolicy {
45 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
46 match self {
47 OutputPolicy::AllOutputs => write!(f, "OutputPolicy::AllOutputs"),
48 OutputPolicy::PrimaryOnly => write!(f, "OutputPolicy::PrimaryOnly"),
49 OutputPolicy::Custom(_) => write!(f, "OutputPolicy::Custom(<filter>)"),
50 }
51 }
52}