pub trait EnvInner<'env> {
type Ro<'tx>: TxRo<'tx>;
type Rw<'tx>: TxRw<'tx>;
// Required methods
fn tx_ro(&self) -> Result<Self::Ro<'_>, RuntimeError>;
fn tx_rw(&self) -> Result<Self::Rw<'_>, RuntimeError>;
fn open_db_ro<T: Table>(
&self,
tx_ro: &Self::Ro<'_>,
) -> Result<impl DatabaseRo<T> + DatabaseIter<T>, RuntimeError>;
fn open_db_rw<T: Table>(
&self,
tx_rw: &Self::Rw<'_>,
) -> Result<impl DatabaseRw<T>, RuntimeError>;
fn create_db<T: Table>(
&self,
tx_rw: &Self::Rw<'_>,
) -> Result<(), RuntimeError>;
fn clear_db<T: Table>(
&self,
tx_rw: &mut Self::Rw<'_>,
) -> Result<(), RuntimeError>;
}
Expand description
The inner Env
type.
This type is created with Env::env_inner
and represents
the type able to generate transactions and open tables.
§Locking behavior
As noted in Env::env_inner
, this is a RwLockReadGuard
when using the heed
backend, be aware of this and do
not hold onto an EnvInner
for a long time.
§Tables
Note that when opening tables with EnvInner::open_db_ro
,
they must be created first or else it will return error.
See EnvInner::create_db
for creating tables.
§Invariant
The first time you open/create tables, you must use EnvInner::create_db
to set the proper flags / Key
comparison for the heed
backend.
Subsequent table opens will follow the flags/ordering, but only if
EnvInner::create_db
was the first function to open/create it.
Required Associated Types§
Required Methods§
Sourcefn tx_ro(&self) -> Result<Self::Ro<'_>, RuntimeError>
fn tx_ro(&self) -> Result<Self::Ro<'_>, RuntimeError>
Sourcefn tx_rw(&self) -> Result<Self::Rw<'_>, RuntimeError>
fn tx_rw(&self) -> Result<Self::Rw<'_>, RuntimeError>
Sourcefn open_db_ro<T: Table>(
&self,
tx_ro: &Self::Ro<'_>,
) -> Result<impl DatabaseRo<T> + DatabaseIter<T>, RuntimeError>
fn open_db_ro<T: Table>( &self, tx_ro: &Self::Ro<'_>, ) -> Result<impl DatabaseRo<T> + DatabaseIter<T>, RuntimeError>
Open a database in read-only mode.
The returned value can have DatabaseRo
& DatabaseIter
functions called on it.
This will open the database Table
passed as a generic to this function.
let db = env_inner.open_db_ro::<Table>(&tx_ro);
// ^ ^
// database table table metadata
// (name, key/value type)
§Errors
This will only return RuntimeError::Io
on normal errors.
If the specified table is not created upon before this function is called,
this will return RuntimeError::TableNotFound
.
§Invariant
The first time you open/create tables, you must use EnvInner::create_db
to set the proper flags / Key
comparison for the heed
backend.
Subsequent table opens will follow the flags/ordering, but only if
EnvInner::create_db
was the first function to open/create it.
Sourcefn open_db_rw<T: Table>(
&self,
tx_rw: &Self::Rw<'_>,
) -> Result<impl DatabaseRw<T>, RuntimeError>
fn open_db_rw<T: Table>( &self, tx_rw: &Self::Rw<'_>, ) -> Result<impl DatabaseRw<T>, RuntimeError>
Open a database in read/write mode.
All DatabaseRo
functions are also callable
with the returned DatabaseRw
structure.
Note that DatabaseIter
functions are not
available to DatabaseRw
structures.
This will open the database Table
passed as a generic to this function.
§Errors
This will only return RuntimeError::Io
on errors.
§Invariant
The first time you open/create tables, you must use EnvInner::create_db
to set the proper flags / Key
comparison for the heed
backend.
Subsequent table opens will follow the flags/ordering, but only if
EnvInner::create_db
was the first function to open/create it.
Sourcefn create_db<T: Table>(&self, tx_rw: &Self::Rw<'_>) -> Result<(), RuntimeError>
fn create_db<T: Table>(&self, tx_rw: &Self::Rw<'_>) -> Result<(), RuntimeError>
Create a database table.
This will create the database Table
passed as a generic to this function.
§Errors
This will only return RuntimeError::Io
on errors.
§Invariant
The first time you open/create tables, you must use EnvInner::create_db
to set the proper flags / Key
comparison for the heed
backend.
Subsequent table opens will follow the flags/ordering, but only if
EnvInner::create_db
was the first function to open/create it.
Sourcefn clear_db<T: Table>(
&self,
tx_rw: &mut Self::Rw<'_>,
) -> Result<(), RuntimeError>
fn clear_db<T: Table>( &self, tx_rw: &mut Self::Rw<'_>, ) -> Result<(), RuntimeError>
Clear all (key, value)
’s from a database table.
This will delete all key and values in the passed
T: Table
, but the table itself will continue to exist.
Note that this operation is tied to tx_rw
, as such this
function’s effects can be aborted using TxRw::abort
.
§Errors
This will return RuntimeError::Io
on normal errors.
If the specified table is not created upon before this function is called,
this will return RuntimeError::TableNotFound
.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.