pub struct Subspace { /* private fields */ }
Expand description
Represents a well-defined region of keyspace in a FoundationDB database
It provides a convenient way to use FoundationDB tuples to define namespaces for different categories of data. The namespace is specified by a prefix tuple which is prepended to all tuples packed by the subspace. When unpacking a key with the subspace, the prefix tuple will be removed from the result.
As a best practice, API clients should use at least one subspace for application data. For general guidance on subspace usage, see the Subspaces section of the Developer Guide.
Implementations§
Source§impl Subspace
impl Subspace
Sourcepub fn all() -> Subspace
pub fn all() -> Subspace
all
returns the Subspace corresponding to all keys in a FoundationDB database.
Sourcepub fn from_bytes(prefix: impl Into<Vec<u8>>) -> Subspace
pub fn from_bytes(prefix: impl Into<Vec<u8>>) -> Subspace
Returns a new Subspace from the provided bytes.
Sourcepub fn into_bytes(self) -> Vec<u8> ⓘ
pub fn into_bytes(self) -> Vec<u8> ⓘ
Convert into prefix key bytes
Sourcepub fn subspace<T>(&self, t: &T) -> Subspacewhere
T: TuplePack,
pub fn subspace<T>(&self, t: &T) -> Subspacewhere
T: TuplePack,
Returns a new Subspace whose prefix extends this Subspace with a given tuple encodable.
Sourcepub fn pack<T>(&self, t: &T) -> Vec<u8> ⓘwhere
T: TuplePack,
pub fn pack<T>(&self, t: &T) -> Vec<u8> ⓘwhere
T: TuplePack,
Returns the key encoding the specified Tuple with the prefix of this Subspace prepended.
Sourcepub fn pack_with_versionstamp<T>(&self, t: &T) -> Vec<u8> ⓘwhere
T: TuplePack,
pub fn pack_with_versionstamp<T>(&self, t: &T) -> Vec<u8> ⓘwhere
T: TuplePack,
Returns the key encoding the specified Tuple with the prefix of this Subspace prepended, with a versionstamp.
Sourcepub fn unpack<'de, T>(&self, key: &'de [u8]) -> Result<T, PackError>where
T: TupleUnpack<'de>,
pub fn unpack<'de, T>(&self, key: &'de [u8]) -> Result<T, PackError>where
T: TupleUnpack<'de>,
unpack
returns the Tuple encoded by the given key with the prefix of this Subspace
removed. unpack
will return an error if the key is not in this Subspace or does not
encode a well-formed Tuple.
Sourcepub fn is_start_of(&self, key: &[u8]) -> bool
pub fn is_start_of(&self, key: &[u8]) -> bool
is_start_of
returns true if the provided key starts with the prefix of this Subspace,
indicating that the Subspace logically contains the key.