cratefield-core 0.3.0

Factory Zero harness kernel: Module trait, Harness builder, ports, errors
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
//! The `KeyValue` port (architecture section 5): KV on Workers, Redis later.

use async_trait::async_trait;
use std::time::Duration;
use thiserror::Error;

#[derive(Debug, Clone, Error)]
pub enum KvError {
    #[error("key-value operation failed: {0}")]
    Operation(String),
}

#[async_trait]
pub trait KeyValue: Send + Sync {
    async fn get(&self, key: &str) -> Result<Option<String>, KvError>;
    async fn put(&self, key: &str, value: &str, ttl: Option<Duration>) -> Result<(), KvError>;
    async fn delete(&self, key: &str) -> Result<(), KvError>;
}