pub struct ReadVersion(/* private fields */);Expand description
Stable numeric cursor for a committed database state.
ReadVersion is the public identifier callers use when they want to open a
Snapshot at a specific historical state. Values are
database-scoped: a read version is meaningful only for the database lineage
that produced it, even if another database happens to contain the same
numeric value.
Use Db::latest_read_version to capture
the newest visible state, and Db::snapshot_at to
validate and pin a version before reading. Versions older than
Db::oldest_retained_read_version
are expired and must not be read by falling back to latest.
§Examples
use trine_kv::{Db, DbOptions, ReadVersion};
let db = Db::open_sync(DbOptions::memory())?;
assert_eq!(db.latest_read_version(), ReadVersion::ZERO);
db.put_sync(b"k", b"v1")?;
let version = db.latest_read_version();
let keep_version = db.snapshot_at(version)?;
db.put_sync(b"k", b"v2")?;
let snapshot = db.snapshot_at(version)?;
assert_eq!(db.get_at_sync(&snapshot, b"k")?, Some(b"v1".to_vec()));
drop(keep_version);Implementations§
Source§impl ReadVersion
impl ReadVersion
Sourcepub const ZERO: Self
pub const ZERO: Self
Read version for the empty database state before the first successful state-changing write.
Sourcepub const fn from_u64(value: u64) -> Self
pub const fn from_u64(value: u64) -> Self
Creates a read version from its stable numeric cursor value.
The value is suitable for application-owned cursors that were
previously obtained from this same database lineage. Creating a
ReadVersion from a number does not prove the version is still
retained; call Db::snapshot_at to validate
it before reading.
Sourcepub const fn as_u64(self) -> u64
pub const fn as_u64(self) -> u64
Returns the stable numeric cursor value.
Applications may persist this value and later rebuild it with
ReadVersion::from_u64. The number is a public cursor, not a promise
about Trine’s internal commit allocation machinery.
Trait Implementations§
Source§impl Clone for ReadVersion
impl Clone for ReadVersion
Source§fn clone(&self) -> ReadVersion
fn clone(&self) -> ReadVersion
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more