-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
11e15ed
commit 57f5cbc
Showing
3 changed files
with
50 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,48 @@ | ||
use std::sync::Arc; | ||
use tokio::sync::Mutex; | ||
|
||
use crate::wit::balius::app::kv as wit; | ||
|
||
pub use wit::{Host as CustomKv, KvError, Payload}; | ||
|
||
#[derive(Clone)] | ||
pub enum Kv { | ||
Mock, | ||
Custom(Arc<Mutex<dyn wit::Host + Send + Sync>>), | ||
} | ||
|
||
#[async_trait::async_trait] | ||
impl wit::Host for Kv { | ||
async fn get_value(&mut self, key: String) -> Result<wit::Payload, wit::KvError> { | ||
todo!() | ||
async fn get_value(&mut self, key: String) -> Result<Payload, KvError> { | ||
match self { | ||
Self::Mock => todo!(), | ||
Self::Custom(kv) => { | ||
let mut lock = kv.lock().await; | ||
lock.get_value(key).await | ||
} | ||
} | ||
} | ||
|
||
async fn set_value(&mut self, key: String, value: wit::Payload) -> Result<(), wit::KvError> { | ||
println!("{}:{}", key, hex::encode(value)); | ||
|
||
Ok(()) | ||
async fn set_value(&mut self, key: String, value: Payload) -> Result<(), KvError> { | ||
match self { | ||
Self::Mock => { | ||
println!("{}:{}", key, hex::encode(value)); | ||
Ok(()) | ||
} | ||
Self::Custom(kv) => { | ||
let mut lock = kv.lock().await; | ||
lock.set_value(key, value).await | ||
} | ||
} | ||
} | ||
|
||
async fn list_values(&mut self, prefix: String) -> Result<Vec<String>, wit::KvError> { | ||
todo!() | ||
async fn list_values(&mut self, prefix: String) -> Result<Vec<String>, KvError> { | ||
match self { | ||
Self::Mock => todo!(), | ||
Self::Custom(kv) => { | ||
let mut lock = kv.lock().await; | ||
lock.list_values(prefix).await | ||
} | ||
} | ||
} | ||
} |
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