Skip to content

Commit

Permalink
v0.5:fastn calling fastn_runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
amitu committed Nov 26, 2024
1 parent bb2aea1 commit a270970
Show file tree
Hide file tree
Showing 7 changed files with 473 additions and 12 deletions.
45 changes: 41 additions & 4 deletions fastn-runtime/src/tdoc.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
use fastn_resolved::Definition;
use indexmap::IndexMap;

pub struct TDoc<'a> {
pub name: &'a str,
pub definitions: indexmap::IndexMap<String, fastn_resolved::Definition>,
Expand All @@ -20,6 +17,7 @@ impl TDoc<'_> {
}
}

#[cfg(feature = "owned-tdoc")]
impl<'a> fastn_resolved::tdoc::TDoc for TDoc<'a> {
fn get_opt_function(&self, name: &str) -> Option<fastn_resolved::Function> {
match self.get(name) {
Expand Down Expand Up @@ -53,7 +51,46 @@ impl<'a> fastn_resolved::tdoc::TDoc for TDoc<'a> {
}
}

fn definitions(&self) -> &IndexMap<String, Definition> {
fn definitions(&self) -> &indexmap::IndexMap<String, fastn_resolved::Definition> {
&self.definitions
}
}

#[cfg(not(feature = "owned-tdoc"))]
impl<'a> fastn_resolved::tdoc::TDoc for TDoc<'a> {
fn get_opt_function(&self, name: &str) -> Option<&fastn_resolved::Function> {
match self.get(name) {
Some(fastn_resolved::Definition::Function(f)) => Some(f),
_ => None,
}
}

fn get_opt_record(&self, name: &str) -> Option<&fastn_resolved::Record> {
match self.get(name) {
Some(fastn_resolved::Definition::Record(f)) => Some(f),
_ => None,
}
}

fn name(&self) -> &str {
self.name
}

fn get_opt_component(&self, name: &str) -> Option<&fastn_resolved::ComponentDefinition> {
match self.get(name) {
Some(fastn_resolved::Definition::Component(f)) => Some(f),
_ => None,
}
}

fn get_opt_web_component(&self, name: &str) -> Option<&fastn_resolved::WebComponentDefinition> {
match self.get(name) {
Some(fastn_resolved::Definition::WebComponent(f)) => Some(f),
_ => None,
}
}

fn definitions(&self) -> &indexmap::IndexMap<String, fastn_resolved::Definition> {
&self.definitions
}
}
Loading

0 comments on commit a270970

Please sign in to comment.