Skip to main content

omnia_wasi_keyvalue/host/
resource.rs

1use std::fmt::Debug;
2use std::ops::Deref;
3use std::sync::Arc;
4
5pub use omnia::FutureResult;
6
7/// Providers implement the [`Bucket`] trait to allow the host to
8/// interact with different backend buckets (stores).
9pub trait Bucket: Debug + Send + Sync + 'static {
10    /// The name of the bucket.
11    fn name(&self) -> &'static str;
12
13    /// Get the value associated with the key.
14    fn get(&self, key: String) -> FutureResult<Option<Vec<u8>>>;
15
16    /// Set the value associated with the key.
17    fn set(&self, key: String, value: Vec<u8>) -> FutureResult<()>;
18
19    /// Delete the value associated with the key.
20    fn delete(&self, key: String) -> FutureResult<()>;
21
22    /// Check if the entry exists.
23    fn exists(&self, key: String) -> FutureResult<bool>;
24
25    /// List all keys in the bucket.
26    fn keys(&self) -> FutureResult<Vec<String>>;
27}
28
29/// Proxy for a Key-Value bucket.
30#[derive(Clone, Debug)]
31pub struct BucketProxy(pub Arc<dyn Bucket>);
32
33impl Deref for BucketProxy {
34    type Target = Arc<dyn Bucket>;
35
36    fn deref(&self) -> &Self::Target {
37        &self.0
38    }
39}
40
41/// CAS (Compare-And-Swap) operation handle.
42#[derive(Clone, Debug)]
43pub struct Cas {
44    /// The key associated with the CAS operation.
45    pub key: String,
46
47    /// The current value associated with the key.
48    pub current: Option<Vec<u8>>,
49}