Module acid_store::repo::version
source · Available on crate feature
repo-version
only.Expand description
An object store with support for content versioning.
This module contains the VersionRepo
repository type.
This repository is an object store like KeyRepo
, except it supports storing multiple
versions of each object. The current version of each object is mutable, while past versions are
read-only.
Like other repositories, changes made to the repository are not persisted to the data store
until Commit::commit
is called. For details about deduplication, compression,
encryption, and locking, see the module-level documentation for crate::repo
.
Examples
Create a version of an object, delete the object’s contents, and then restore from the version.
use std::io::{Read, Write};
use acid_store::repo::{OpenMode, OpenOptions, Object, version::VersionRepo, RepoConfig};
use acid_store::store::MemoryConfig;
fn main() -> acid_store::Result<()> {
let mut repository: VersionRepo<String> = OpenOptions::new()
.mode(OpenMode::CreateNew)
.open(&MemoryConfig::new())?;
// Insert a new object and write some data to it.
let mut object = repository.insert(String::from("Key")).unwrap();
object.write_all(b"Original data")?;
object.commit()?;
drop(object);
// Create a new, read-only version of this object.
let version = repository.create_version("Key").unwrap();
// Modify the current version of the object.
let mut object = repository.object("Key").unwrap();
object.set_len(0)?;
drop(object);
// Restore from the version we created earlier.
repository.restore_version("Key", version.id());
// Check the contents.
let mut object = repository.object("Key").unwrap();
let mut contents = Vec::new();
object.read_to_end(&mut contents)?;
assert_eq!(contents, b"Original data");
Ok(())
}
Structs
- An iterator over the keys in a
VersionRepo
. - Information about a version in a
VersionRepo
. - An object store with support for content versioning.
- An iterator over the versions of a key in a
VersionRepo
.