logix_type/type_trait/
mod.rs1mod impl_trait;
4
5use crate::{error::Result, parser::LogixParser, span::SourceSpan};
6pub use logix_vfs::LogixVfs;
7
8#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
10pub struct Value<T> {
11 pub value: T,
12 pub span: SourceSpan,
13}
14
15impl<T> Value<T> {
16 pub fn map<R>(self, f: impl FnOnce(T) -> R) -> Value<R> {
17 Value {
18 span: self.span,
19 value: f(self.value),
20 }
21 }
22
23 pub fn join_with_span(mut self, span: SourceSpan) -> Self {
24 self.span = self.span.join(&span);
25 self
26 }
27}
28
29#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Clone)]
31pub enum LogixValueDescriptor {
32 Native,
34 Tuple {
36 members: Vec<&'static LogixTypeDescriptor>,
37 },
38 Struct {
40 members: Vec<(&'static str, &'static LogixTypeDescriptor)>,
41 },
42 Enum { variants: Vec<LogixTypeDescriptor> },
44}
45
46#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Clone)]
48pub struct LogixTypeDescriptor {
49 pub name: &'static str,
51 pub doc: &'static str,
53 pub value: LogixValueDescriptor,
55}
56
57pub trait LogixType: Sized {
59 fn descriptor() -> &'static LogixTypeDescriptor;
61 fn default_value() -> Option<Self>;
63 fn logix_parse<FS: LogixVfs>(p: &mut LogixParser<FS>) -> Result<Value<Self>>;
65}