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 offset for API 520 and later.
Incomplete stamps append a four-byte offset. For earlier runtime APIs, use
Self::pack_with_versionstamp_for_key. Complete stamps are packed without
an offset suffix.
Sourcepub fn pack_with_versionstamp_for_key<T>(
&self,
t: &T,
api_version: i32,
) -> Vec<u8> ⓘwhere
T: TuplePack,
pub fn pack_with_versionstamp_for_key<T>(
&self,
t: &T,
api_version: i32,
) -> Vec<u8> ⓘwhere
T: TuplePack,
Pack a tuple key with this subspace’s prefix for the selected runtime API.
See pack_with_versionstamp_for_key for the encoding and version contract.
The offset includes the entire prefix, including any incomplete stamp in
the subspace itself. A raw prefix supplied via Self::from_bytes is
opaque: only stamps in the tuple are tracked in that case.
§Panics
Panics if there are multiple incomplete stamps, the encoded size does not
fit in u32, or a legacy key’s stamp offset does not fit in u16.
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.