12个版本 (5个稳定版)
5.0.0 | 2023年4月12日 |
---|---|
4.0.0 | 2020年3月3日 |
3.0.0 | 2019年7月27日 |
2.0.0 | 2018年12月18日 |
0.3.0 | 2018年3月21日 |
#558 in 异步
1,051 下载/月
用于 10 个crates (8 个直接使用)
14KB
57 代码行
random-access-storage
实现随机访问实例的抽象接口。
安装
$ cargo add random-access-storage
另请参阅
- 原始JavaScript random-access-storage
许可
MIT OR Apache-2.0
lib.rs
:
实现随机访问实例的抽象接口
此包定义了共享的[RandomAccess]特质,使其能够创建用于读取、写入和删除字节的不同的后端。通过共享接口,实现可以根据需求和环境轻松交换。
已知实现
完整的[RandomAccess]实现包括
- random-access-memory 用于内存存储
- random-access-disk 用于磁盘存储
示例
您自己的随机访问后端可以按如下方式实现
use random_access_storage::{RandomAccess, RandomAccessError};
use async_trait::async_trait;
struct MyRandomAccess {
// Add fields here
}
#[async_trait]
impl RandomAccess for MyRandomAccess {
async fn write(&mut self, _offset: u64, _data: &[u8]) -> Result<(), RandomAccessError> {
unimplemented!();
}
async fn read(&mut self, _offset: u64, _length: u64) -> Result<Vec<u8>, RandomAccessError> {
unimplemented!();
}
async fn del(&mut self, _offset: u64, _length: u64) -> Result<(), RandomAccessError> {
unimplemented!();
}
async fn truncate(&mut self, _length: u64) -> Result<(), RandomAccessError> {
unimplemented!();
}
async fn len(&mut self) -> Result<u64, RandomAccessError> {
unimplemented!();
}
async fn is_empty(&mut self) -> Result<bool, RandomAccessError> {
unimplemented!();
}
async fn sync_all(&mut self) -> Result<(), RandomAccessError> {
unimplemented!();
}
}
依赖项
~310–780KB
~18K SLoC