bevy_lunex_core/code/
types.rs1use bevy::{utils::thiserror::Error, ecs::component::Component};
2use pathio::PathioError;
3use crate::Container;
4
5#[derive(Clone, Component, Debug, Error, PartialEq)]
6pub enum LunexError {
7 #[error("Container from merging branch was not dropped before merging")]
9 ContainerConflict,
10
11 #[error("Duplicate name conflict for '{0:}' when trying to merge directory")]
13 DuplicateName (String),
14
15 #[error("Name '{0:}' is already in use")]
17 NameInUse (String),
18
19 #[error("Path '{0:}' is not allowed")]
21 InvalidPath (String),
22
23 #[error("Unable to locate '{0:}' branch")]
25 NoBranch (String),
26
27
28
29
30 #[error("could not find '{path:}': {cause:}")]
32 FetchError {
33 path: String,
34 cause: Box<LunexError>,
35 },
36}
37impl From<PathioError> for LunexError {
38 fn from(value: PathioError) -> Self {
39 match value {
40 PathioError::FileConflict => LunexError::ContainerConflict,
41 PathioError::DuplicateName (v) => LunexError::DuplicateName (v),
42 PathioError::NameInUse (v) => LunexError::NameInUse (v),
43 PathioError::NoDirectory (v) => LunexError::NoBranch (v),
44 PathioError::NoFile (_) => panic!("API should NOT ALLOW you to get this error"),
45 PathioError::InvalidPath (v) => LunexError::InvalidPath (v),
46 }
47 }
48}
49
50
51#[derive(Clone, Component, Debug, Default, PartialEq)]
55pub struct DataWrap<T:Default> {
56 container: Container,
57 data: Option<T>,
58}
59impl <T: Default> DataWrap<T> {
60 pub fn new(container: Container) -> Self {
61 DataWrap {
62 container,
63 data: None,
64 }
65 }
66 pub fn container(&self) -> &Container {
68 &self.container
69 }
70 pub fn container_mut(&mut self) -> &mut Container {
72 &mut self.container
73 }
74 pub fn data(&mut self) -> &T {
77 if let None = &self.data {
78 self.data = Some(T::default());
79 }
80 match &self.data {
81 Some(t) => t,
82 None => unreachable!()
83 }
84 }
85 pub fn data_mut(&mut self) -> &mut T {
87 if let None = &self.data {
88 self.data = Some(T::default());
89 }
90 match &mut self.data {
91 Some(t) => t,
92 None => unreachable!()
93 }
94 }
95}
96
97#[derive(Clone, Component, Debug, Default, PartialEq)]
98pub struct Size {
99 pub width: f32,
100 pub height: f32,
101}
102
103#[derive(Clone, Copy, Component, Debug, PartialEq)]
107pub enum Modifier<T> {
108 Add (T),
109 Set (T),
110}