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