-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #29 from G-Core/feat/dictionary
Support for dictionary interface
- Loading branch information
Showing
11 changed files
with
108 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
[package] | ||
name = "dictionary" | ||
version.workspace = true | ||
edition.workspace = true | ||
publish.workspace = true | ||
authors.workspace = true | ||
description = "dictionary host function" | ||
|
||
[dependencies] | ||
reactor = { path = "../reactor" } | ||
anyhow = {workspace = true} | ||
tracing = {workspace = true} | ||
async-trait = {workspace = true} | ||
wasmtime = {workspace = true} | ||
|
||
[lints] | ||
workspace = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
use std::collections::HashMap; | ||
use std::ops::{Deref, DerefMut}; | ||
use async_trait::async_trait; | ||
use reactor::gcore::fastedge::dictionary; | ||
|
||
#[derive(Clone)] | ||
pub struct Dictionary{ | ||
inner: HashMap<String, String> | ||
} | ||
|
||
#[async_trait] | ||
impl dictionary::Host for Dictionary { | ||
async fn get(&mut self, name: String) -> anyhow::Result<Option<String>> { | ||
Ok(self.inner.get(&name).map(|v| v.to_string())) | ||
} | ||
} | ||
|
||
impl Default for Dictionary { | ||
fn default() -> Self { | ||
Self{ | ||
inner: Default::default() | ||
} | ||
} | ||
} | ||
|
||
impl Dictionary { | ||
pub fn new() -> Self { | ||
Self{ | ||
inner: Default::default() | ||
} | ||
} | ||
} | ||
|
||
impl Deref for Dictionary { | ||
type Target = HashMap<String, String>; | ||
|
||
fn deref(&self) -> &Self::Target { | ||
&self.inner | ||
} | ||
} | ||
|
||
impl DerefMut for Dictionary { | ||
fn deref_mut(&mut self) -> &mut Self::Target { | ||
&mut self.inner | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule sdk
updated
5 files
+164 −105 | Cargo.lock | |
+3 −3 | Cargo.toml | |
+8 −1 | src/lib.rs | |
+6 −0 | wit/dictionary.wit | |
+2 −0 | wit/world.wit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters