12个版本
1.0.0-alpha.6 | 2024年8月6日 |
---|---|
1.0.0-alpha.5 | 2024年7月26日 |
1.0.0-alpha.2 |
|
0.11.0 | 2024年6月4日 |
0.5.0-beta.8 | 2021年3月31日 |
#18 in #distributed-computing
607 每月下载量
用于 7 crates
1.5MB
38K SLoC
⚠️ 警告 ⚠️
此crate旨在供Zenoh内部使用。
lib.rs
:
⚠️ 警告 ⚠️
TODO:示例已过时,请重写
此crate应被视为不稳定,因为我们可能会随时更改API。
此crate提供Zenoh后端库需要实现的特性
此类库还必须声明一个具有create_volume()
操作并带有#[no_mangle]
属性的操作,作为后端创建的入口点。
示例
use std::sync::Arc;
use async_trait::async_trait;
use zenoh::{key_expr::OwnedKeyExpr, prelude::*, time::Timestamp, internal::Value};
use zenoh_backend_traits::*;
use zenoh_backend_traits::config::*;
#[no_mangle]
pub fn create_volume(config: VolumeConfig) -> ZResult<Box<dyn Volume>> {
Ok(Box::new(MyVolumeType { config }))
}
// Your Backend implementation
struct MyVolumeType {
config: VolumeConfig,
}
#[async_trait]
impl Volume for MyVolumeType {
fn get_admin_status(&self) -> serde_json::Value {
// This operation is called on GET operation on the admin space for the Volume
// Here we reply with a static status (containing the configuration properties).
// But we could add dynamic properties for Volume monitoring.
self.config.to_json_value()
}
fn get_capability(&self) -> Capability {
// This operation is used to confirm if the volume indeed supports
// the capabilities requested by the configuration
Capability{
persistence: Persistence::Volatile,
history: History::Latest,
read_cost: 0,
}
}
async fn create_storage(&self, properties: StorageConfig) -> ZResult<Box<dyn Storage>> {
// The properties are the ones passed via a PUT in the admin space for Storage creation.
Ok(Box::new(MyStorage::new(properties).await?))
}
}
// Your Storage implementation
struct MyStorage {
config: StorageConfig,
}
impl MyStorage {
async fn new(config: StorageConfig) -> ZResult<MyStorage> {
Ok(MyStorage { config })
}
}
#[async_trait]
impl Storage for MyStorage {
fn get_admin_status(&self) -> serde_json::Value {
// This operation is called on GET operation on the admin space for the Storage
// Here we reply with a static status (containing the configuration properties).
// But we could add dynamic properties for Storage monitoring.
self.config.to_json_value()
}
async fn put(&mut self, key: Option<OwnedKeyExpr>, value: Value, timestamp: Timestamp) -> ZResult<StorageInsertionResult> {
// the key will be None if it exactly matched with the strip_prefix
// create a storage specific special structure to store it
// Store the data with timestamp
// @TODO:
// store (key, value, timestamp)
return Ok(StorageInsertionResult::Inserted);
// - if any issue: drop
// return Ok(StorageInsertionResult::Outdated);
}
async fn delete(&mut self, key: Option<OwnedKeyExpr>, timestamp: Timestamp) -> ZResult<StorageInsertionResult> {
// @TODO:
// delete the actual entry from storage
return Ok(StorageInsertionResult::Deleted);
}
// When receiving a GET operation
async fn get(&mut self, key_expr: Option<OwnedKeyExpr>, parameters: &str) -> ZResult<Vec<StoredData>> {
// @TODO:
// get the data associated with key_expr and return it
// NOTE: in case parameters is not empty something smarter should be done with returned data...
Ok(Vec::new())
}
// To get all entries in the datastore
async fn get_all_entries(&self) -> ZResult<Vec<(Option<OwnedKeyExpr>, Timestamp)>> {
// @TODO: get the list of (key, timestamp) in the datastore
Ok(Vec::new())
}
}
依赖项
~25–38MB
~584K SLoC