fastn_resolved/
lib.rs

1#![allow(clippy::derive_partial_eq_without_eq, clippy::get_first)]
2#![deny(unused_crate_dependencies)]
3#![warn(clippy::used_underscore_binding)]
4
5extern crate self as fastn_resolved;
6
7mod component;
8pub mod evalexpr;
9mod expression;
10mod function;
11mod kind;
12mod module_thing;
13mod or_type;
14mod record;
15mod value;
16mod variable;
17mod web_component;
18
19pub use component::{
20    Argument, ComponentDefinition, ComponentInvocation, ComponentSource, Event, EventName, Loop,
21    Property, PropertySource,
22};
23pub use expression::Expression;
24pub use function::{Function, FunctionCall, FunctionExpression};
25pub use kind::{Kind, KindData};
26pub use module_thing::ModuleThing;
27pub use or_type::{OrType, OrTypeVariant};
28pub use record::{AccessModifier, Field, Record};
29pub use value::{PropertyValue, PropertyValueSource, Value};
30pub use variable::{ConditionalValue, Variable};
31pub use web_component::WebComponentDefinition;
32pub type Map<T> = std::collections::BTreeMap<String, T>;
33
34#[derive(Debug, Clone, PartialEq, serde::Deserialize, serde::Serialize)]
35pub enum Definition {
36    Record(fastn_resolved::Record),
37    OrType(fastn_resolved::OrType),
38    OrTypeWithVariant {
39        or_type: String,
40        variant: fastn_resolved::OrTypeVariant,
41    },
42    Variable(fastn_resolved::Variable),
43    Component(fastn_resolved::ComponentDefinition),
44    WebComponent(fastn_resolved::WebComponentDefinition),
45    Function(fastn_resolved::Function),
46    /// what is this?
47    Export {
48        from: String,
49        to: String,
50        line_number: usize,
51    },
52}
53
54impl Definition {
55    pub fn name(&self) -> String {
56        match self {
57            fastn_resolved::Definition::Record(r) => r.name.clone(),
58            fastn_resolved::Definition::OrType(o) => o.name.clone(),
59            fastn_resolved::Definition::OrTypeWithVariant { or_type, .. } => or_type.clone(),
60            fastn_resolved::Definition::Variable(v) => v.name.to_string(),
61            fastn_resolved::Definition::Component(c) => c.name.to_string(),
62            fastn_resolved::Definition::Function(f) => f.name.to_string(),
63            fastn_resolved::Definition::WebComponent(w) => w.name.to_string(),
64            fastn_resolved::Definition::Export { to, .. } => to.to_string(),
65        }
66    }
67
68    pub fn line_number(&self) -> usize {
69        match self {
70            Definition::Record(r) => r.line_number,
71            Definition::Variable(v) => v.line_number,
72            Definition::Component(c) => c.line_number,
73            Definition::Function(f) => f.line_number,
74            Definition::OrType(o) => o.line_number,
75            Definition::OrTypeWithVariant { variant, .. } => variant.line_number(),
76            Definition::WebComponent(w) => w.line_number,
77            Definition::Export { line_number, .. } => *line_number,
78        }
79    }
80
81    pub fn component(self) -> Option<fastn_resolved::ComponentDefinition> {
82        match self {
83            fastn_resolved::Definition::Component(v) => Some(v),
84            _ => None,
85        }
86    }
87}