xref: /DragonReach/src/unit/target/mod.rs (revision f206f17adf7b13bcbc7a739d44eada5c810b68fe)
1 use super::{BaseUnit, Unit};
2 use crate::error::ParseError;
3 use crate::parse::Segment;
4 use crate::parse::parse_target::TargetParser;
5 use core::ops::Deref;
6 use cfg_if::cfg_if;
7 
8 cfg_if!{
9     if #[cfg(target_os = "dragonos")]{
10         use drstd as std;
11         use std::rc::Rc;
12         use std::vec::Vec;
13     }else{
14         use std::rc::Rc;
15         use std::vec::Vec;
16     }
17 }
18 
19 #[derive(Default)]
20 pub struct TargetUnit {
21     unit_base: BaseUnit,
22     //targets: Vec<Rc<dyn Unit>>,
23 }
24 
25 impl Deref for TargetUnit {
26     type Target = TargetUnit;
27     fn deref(&self) -> &Self::Target {
28         &self
29     }
30 }
31 
32 impl Unit for TargetUnit {
33     fn as_any(&self) -> &dyn core::any::Any {
34         self
35     }
36 
37     fn from_path(path: &str) -> Result<Rc<Self>, ParseError>
38     where
39         Self: Sized,
40     {
41         return TargetParser::parse(path);
42     }
43 
44     fn set_attr(&mut self, segement: Segment, attr: &str, val: &str) -> Result<(), ParseError> {
45         Ok(())
46     }
47 
48     fn set_unit_base(&mut self, base: BaseUnit) {
49         self.unit_base = base;
50     }
51 
52     fn unit_type(&self) -> super::UnitType {
53         return self.unit_base.unit_type;
54     }
55 }
56