gmt_dos_actors/system/
implementations.rs1use crate::{
2 actor::{Actor, PlainActor},
3 framework::{
4 model::{Check, CheckError, Task, TaskError},
5 network::{ActorOutput, AddActorInput},
6 },
7 prelude::{AddActorOutput, GetName, Model, Unknown},
8 ActorError,
9};
10
11use super::{
12 interfaces::{System, SystemInput, SystemOutput},
13 Sys,
14};
15
16#[async_trait::async_trait]
17impl<T> Task for Sys<T>
18where
19 T: System,
20 for<'a> &'a T: IntoIterator<Item = Box<&'a dyn Check>>,
21 Box<T>: IntoIterator<Item = Box<dyn Task>>,
22{
23 async fn async_run(&mut self) -> std::result::Result<(), TaskError> {
24 todo!()
25 }
26
27 async fn task(mut self: Box<Self>) -> std::result::Result<(), TaskError> {
28 let name = self.name();
29 let verbose = self.verbose;
30 let q = *self;
31 let w = q.sys;
32 let b = Box::new(w);
33 Model::<Unknown>::from_iter(b)
34 .name(name)
35 .verbose(verbose)
36 .skip_check()
37 .run()
38 .await?;
39 Ok(())
40 }
41
42 fn as_plain(&self) -> PlainActor {
43 self.plain()
44 }
45}
46
47impl<T> Check for Sys<T>
48where
49 T: System,
50 for<'a> &'a T: IntoIterator<Item = Box<&'a dyn Check>>,
51{
52 fn check_inputs(&self) -> std::result::Result<(), CheckError> {
53 self.into_iter()
54 .map(|a| a.check_inputs())
55 .collect::<Result<Vec<_>, _>>()
56 .map(|_| ())
57 }
58
59 fn check_outputs(&self) -> std::result::Result<(), CheckError> {
60 self.into_iter()
61 .map(|a| a.check_outputs())
62 .collect::<Result<Vec<_>, _>>()
63 .map(|_| ())
64 }
65
66 fn n_inputs(&self) -> usize {
67 self.into_iter()
68 .map(|a: Box<&dyn Check>| a.n_inputs())
69 .sum()
70 }
71 fn n_outputs(&self) -> usize {
72 self.into_iter()
73 .map(|a: Box<&dyn Check>| a.n_outputs())
74 .sum()
75 }
76
77 fn inputs_hashes(&self) -> Vec<u64> {
78 self.into_iter()
79 .flat_map(|a: Box<&dyn Check>| a.inputs_hashes())
80 .collect()
81 }
82
83 fn outputs_hashes(&self) -> Vec<u64> {
84 self.into_iter()
85 .flat_map(|a: Box<&dyn Check>| a.outputs_hashes())
86 .collect()
87 }
88
89 fn _as_plain(&self) -> PlainActor {
90 self.plain()
91 }
92
93 fn is_system(&self) -> bool {
94 true
95 }
96}
97
98impl<T: System> GetName for T {
99 fn get_name(&self) -> String {
100 self.name()
101 }
102}
103
104impl<'a, T, CO, const NI: usize, const NO: usize> AddActorOutput<'a, CO, NI, NO> for Sys<T>
105where
106 T: System,
107 Sys<T>: SystemOutput<CO, NI, NO>,
108 CO: interface::TryUpdate + 'static,
109{
110 fn add_output(&'a mut self) -> ActorOutput<'a, Actor<CO, NI, NO>> {
111 AddActorOutput::add_output(self.output())
112 }
113}
114
115impl<U, T, CI, const NI: usize, const NO: usize> AddActorInput<U, CI, NI, NO> for Sys<T>
116where
117 T: System,
118 Sys<T>: SystemInput<CI, NI, NO>,
119 U: 'static + interface::UniqueIdentifier,
120 CI: interface::TryRead<U> + 'static,
121 ActorError: From<<CI as interface::TryRead<U>>::Error>,
122{
123 fn add_input(&mut self, rx: flume::Receiver<interface::Data<U>>, hash: u64) {
124 AddActorInput::add_input(self.input(), rx, hash)
125 }
126}