xref: /DragonReach/src/unit/target/mod.rs (revision 909e4d102ffeb8646e7346c10b007cb0861226a4)
1 use super::{BaseUnit, Unit};
2 use crate::error::parse_error::ParseError;
3 use crate::parse::parse_target::TargetParser;
4 use crate::parse::Segment;
5 
6 use core::result::Result::{self, Ok};
7 
8 use std::marker::{Send, Sized, Sync};
9 
10 #[derive(Debug, Clone, Default)]
11 pub struct TargetUnit {
12     unit_base: BaseUnit,
13     //targets: Vec<Rc<dyn Unit>>,
14 }
15 
16 impl Unit for TargetUnit {
17     fn as_any(&self) -> &dyn core::any::Any {
18         self
19     }
20 
21     fn from_path(path: &str) -> Result<usize, ParseError>
22     where
23         Self: Sized,
24     {
25         return TargetParser::parse(path);
26     }
27 
28     fn set_attr(&mut self, _segement: Segment, _attr: &str, _val: &str) -> Result<(), ParseError> {
29         Ok(())
30     }
31 
32     fn set_unit_base(&mut self, base: BaseUnit) {
33         self.unit_base = base;
34     }
35 
36     fn unit_type(&self) -> super::UnitType {
37         return self.unit_base.unit_type;
38     }
39 
40     fn unit_base(&self) -> &BaseUnit {
41         return &self.unit_base;
42     }
43 
44     fn unit_id(&self) -> usize {
45         return self.unit_base.unit_id;
46     }
47 
48     fn run(&mut self) -> Result<(), crate::error::runtime_error::RuntimeError> {
49         Ok(())
50     }
51 
52     fn unit_base_mut(&mut self) -> &mut BaseUnit {
53         return &mut self.unit_base;
54     }
55 
56     fn as_mut_any(&mut self) -> &mut dyn std::any::Any {
57         self
58     }
59 
60     fn exit(&mut self) {
61         todo!()
62     }
63 }
64 
65 unsafe impl Sync for TargetUnit {}
66 
67 unsafe impl Send for TargetUnit {}
68