pub struct Store { /* private fields */ }Expand description
A backend opened against a declaration of needs.
Implementations§
Source§impl Store
impl Store
Sourcepub async fn open(config: Config, needs: Needs) -> Result<Store>
pub async fn open(config: Config, needs: Needs) -> Result<Store>
Open config, refusing it if it cannot give every need in needs.
Sourcepub async fn read(&self, key: &str) -> Result<Vec<u8>>
pub async fn read(&self, key: &str) -> Result<Vec<u8>>
Read the whole value at key. A key with no value is Error::NotFound, distinct from a
backend failure.
Sourcepub async fn replace(&self, key: &str, bytes: Vec<u8>) -> Result<()>
pub async fn replace(&self, key: &str, bytes: Vec<u8>) -> Result<()>
Replace the value at key in one step.
Sourcepub async fn delete(&self, key: &str) -> Result<()>
pub async fn delete(&self, key: &str) -> Result<()>
Delete key. Deleting a key that does not exist is not an error.
Sourcepub async fn stat(&self, key: &str) -> Result<Entry>
pub async fn stat(&self, key: &str) -> Result<Entry>
Size and modification time of the value at key. A key with no value (or one that names a
directory) is Error::NotFound. Needs Need::Stat.
Sourcepub async fn list(
&self,
prefix: &str,
after: Option<&str>,
limit: NonZeroUsize,
) -> Result<Page>
pub async fn list( &self, prefix: &str, after: Option<&str>, limit: NonZeroUsize, ) -> Result<Page>
List up to limit keys that start with prefix, in ascending key order, strictly after
after if given (pass the previous page’s Page::next). Needs Need::List and
Need::Stat.
prefix is a plain string prefix of the key, not a directory: "img/a" matches
"img/a.png" and "img/ab/c". OpenDAL only lists directories, so this lists every key
under the prefix’s directory part ("img/") and filters: emulated, and the cost is a
scan of that whole directory tree. Memory is bounded by limit, not by the tree; time is
not, so a large tree is rescanned for every page. Keys that vanish while a page is being
built are left out.
Sourcepub async fn create_if_absent(&self, key: &str, bytes: Vec<u8>) -> Result<()>
pub async fn create_if_absent(&self, key: &str, bytes: Vec<u8>) -> Result<()>
Write bytes at key only if nothing is there yet; otherwise Error::AlreadyExists and
nothing changes. Needs Need::Write and Need::CreateIfAbsent.
Native, never emulated: a backend that cannot do this exclusively is refused at open
(see Need::CreateIfAbsent). On fs that means atomic_write_dir must be unset,
because OpenDAL’s atomic path checks for the key and then renames, which two creators can
both pass. Without it the file is created exclusively but written in place, so a reader
may see a partly written value of a large create. This write is not counted by the
fault-injecting fake.
Sourcepub async fn put_record<R: Record>(&self, key: &str, record: &R) -> Result<()>
pub async fn put_record<R: Record>(&self, key: &str, record: &R) -> Result<()>
Store record under key as a versioned envelope, replacing atomically.
Sourcepub async fn get_record<R: Record>(&self, key: &str) -> Result<Option<R>>
pub async fn get_record<R: Record>(&self, key: &str) -> Result<Option<R>>
Read the record at key: None if absent. An older schema goes through
Record::upgrade; a newer one, or another kind, is refused.
Sourcepub async fn begin_replace(&self, key: &str) -> Result<Replace>
pub async fn begin_replace(&self, key: &str) -> Result<Replace>
Start a replacement that can be written in pieces (the fault-injecting fake applies here
too). Dropping it without commit leaves the
old value in place, but on fs the unfinished temporary file stays in atomic_write_dir
(OpenDAL has no cleanup on drop); sweep that directory at startup. Durability across power
loss is not claimed: OpenDAL syncs the file, not the parent directory, before the rename.