use async_trait::async_trait;
use serde_json::Value;
use iii_sdk::{UpdateOp, UpdateResult, types::SetResult};
struct CustomStateAdapter {
// Your storage implementation
}
#[async_trait]
impl StateAdapter for CustomStateAdapter {
async fn set(&self, scope: &str, key: &str, value: Value) -> anyhow::Result<SetResult> {
// Store the value
Ok(SetResult {
key: key.to_string(),
value: Some(value),
created: true,
})
}
async fn get(&self, scope: &str, key: &str) -> anyhow::Result<Option<Value>> {
// Retrieve the value
Ok(None)
}
async fn delete(&self, scope: &str, key: &str) -> anyhow::Result<()> {
// Delete the key
Ok(())
}
async fn update(
&self,
scope: &str,
key: &str,
ops: Vec<UpdateOp>,
) -> anyhow::Result<UpdateResult> {
// Apply update operations atomically
for op in &ops {
match op {
UpdateOp::Set { path, value } => { /* ... */ },
UpdateOp::Merge { path, value } => { /* ... */ },
UpdateOp::Increment { path, by } => { /* ... */ },
UpdateOp::Decrement { path, by } => { /* ... */ },
UpdateOp::Remove { path } => { /* ... */ },
}
}
Ok(UpdateResult {
key: key.to_string(),
value: None,
})
}
async fn list(&self, scope: &str) -> anyhow::Result<Vec<Value>> {
Ok(vec![])
}
async fn list_groups(&self) -> anyhow::Result<Vec<String>> {
Ok(vec![])
}
async fn destroy(&self) -> anyhow::Result<()> {
Ok(())
}
}