Trait ys_core::ObjectStore

source ·
pub trait ObjectStore {
    type Error: Into<YsError>;

    // Required methods
    fn has(
        &self,
        id: ObjectID
    ) -> impl Future<Output = Result<bool, Self::Error>> + Send;
    fn read(
        &self,
        id: ObjectID
    ) -> impl Future<Output = Result<Vec<u8>, Self::Error>> + Send;
    fn insert(
        &mut self,
        object: &[u8]
    ) -> impl Future<Output = Result<ObjectID, Self::Error>> + Send;
}
Expand description

对象储存位置的通用接口,定义了在内存、目录或网络中存储、读取和检查对象的基本操作。

Required Associated Types§

Required Methods§

source

fn has( &self, id: ObjectID ) -> impl Future<Output = Result<bool, Self::Error>> + Send

检查对象是否存在于存储中。

§参数
  • id: 要检查的对象的唯一标识符。
§返回值
  • Result<bool, Self::Error>: 如果对象存在,返回Result::Ok(true);如果不存在或发生错误,返回Result::Err(error),其中errorSelf::Error类型。
source

fn read( &self, id: ObjectID ) -> impl Future<Output = Result<Vec<u8>, Self::Error>> + Send

从存储中读取对象。

§参数
  • id: 要读取的对象的唯一标识符。
§返回值
  • Result<Option<Vec<u8>>, Self::Error>: 如果对象存在,返回包含对象数据的Vec<u8>Result::Ok;如果对象不存在,返回Result::Ok(None);如果发生错误,返回Result::Err(error),其中errorSelf::Error类型。
source

fn insert( &mut self, object: &[u8] ) -> impl Future<Output = Result<ObjectID, Self::Error>> + Send

将对象插入存储。

§参数
  • object: 要插入存储的对象数据的字节切片。
§返回值
  • Result<ObjectID, Self::Error>: 如果对象成功插入,返回该对象的唯一标识符ObjectIDResult::Ok;如果插入失败,返回Result::Err(error),其中errorSelf::Error类型。

Object Safety§

This trait is not object safe.

Implementors§