Skip to main content

TxMock

Struct TxMock 

pub struct TxMock { /* private fields */ }
Expand description

Mock transaction implementation for testing and development.

Implements both DbTx and DbTxMut traits. All operations are no-ops that return success or default values, suitable for testing database operations without side effects.

Trait Implementations§

§

impl Clone for TxMock

§

fn clone(&self) -> TxMock

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
§

impl DbTx for TxMock

§

fn get<T>( &self, _key: <T as Table>::Key, ) -> Result<Option<<T as Table>::Value>, DatabaseError>
where T: Table,

Retrieves a value by key from the specified table.

Mock behavior: Always returns None regardless of the key. This simulates a table with no data, which is typical for testing scenarios where you want to verify that read operations are called correctly without actually storing data.

§

fn get_by_encoded_key<T>( &self, _key: &<<T as Table>::Key as Encode>::Encoded, ) -> Result<Option<<T as Table>::Value>, DatabaseError>
where T: Table,

Retrieves a value by encoded key from the specified table.

Mock behavior: Always returns None regardless of the encoded key. This is equivalent to Self::get but works with pre-encoded keys.

§

fn commit(self) -> Result<(), DatabaseError>

Commits the transaction.

Mock behavior: Always returns Ok(()), indicating successful commit. No actual data is persisted since this is a mock implementation.

§

fn abort(self)

Aborts the transaction.

Mock behavior: No-op. Since no data is actually stored in the mock, there’s nothing to rollback.

§

fn cursor_read<T>(&self) -> Result<<TxMock as DbTx>::Cursor<T>, DatabaseError>
where T: Table,

Creates a read-only cursor for the specified table.

Mock behavior: Returns a default CursorMock that will not iterate over any data (all cursor operations return None).

§

fn cursor_dup_read<T>( &self, ) -> Result<<TxMock as DbTx>::DupCursor<T>, DatabaseError>
where T: DupSort,

Creates a read-only duplicate cursor for the specified duplicate sort table.

Mock behavior: Returns a default CursorMock that will not iterate over any data (all cursor operations return None).

§

fn entries<T>(&self) -> Result<usize, DatabaseError>
where T: Table,

Returns the number of entries in the specified table.

Mock behavior: Returns the length of the internal _table BTreeMap, which is typically 0 since no data is actually stored.

§

fn disable_long_read_transaction_safety(&mut self)

Disables long read transaction safety checks.

Mock behavior: No-op. This is a performance optimization that doesn’t apply to the mock implementation.

§

type Cursor<T: Table> = CursorMock

Cursor type for this read-only transaction
§

type DupCursor<T: DupSort> = CursorMock

DupCursor type for this read-only transaction
§

fn prefetch(&self, _enabled: bool) -> &Self

Enables or disables best-effort read-ahead for this transaction. Read more
§

impl DbTxMut for TxMock

§

fn put<T>( &self, _key: <T as Table>::Key, _value: <T as Table>::Value, ) -> Result<(), DatabaseError>
where T: Table,

Inserts or updates a key-value pair in the specified table.

Mock behavior: Always returns Ok(()) without actually storing the data. This allows tests to verify that write operations are called correctly without side effects.

§

fn delete<T>( &self, _key: <T as Table>::Key, _value: Option<<T as Table>::Value>, ) -> Result<bool, DatabaseError>
where T: Table,

Deletes a key-value pair from the specified table.

Mock behavior: Always returns Ok(true), indicating successful deletion, without actually removing any data.

§

fn clear<T>(&self) -> Result<(), DatabaseError>
where T: Table,

Clears all entries from the specified table.

Mock behavior: Always returns Ok(()) without actually clearing any data. This simulates successful table clearing for testing purposes.

§

fn cursor_write<T>( &self, ) -> Result<<TxMock as DbTxMut>::CursorMut<T>, DatabaseError>
where T: Table,

Creates a write cursor for the specified table.

Mock behavior: Returns a default CursorMock that will not iterate over any data and all write operations will be no-ops.

§

fn cursor_dup_write<T>( &self, ) -> Result<<TxMock as DbTxMut>::DupCursorMut<T>, DatabaseError>
where T: DupSort,

Creates a write duplicate cursor for the specified duplicate sort table.

Mock behavior: Returns a default CursorMock that will not iterate over any data and all write operations will be no-ops.

§

type CursorMut<T: Table> = CursorMock

Read-Write Cursor type
§

type DupCursorMut<T: DupSort> = CursorMock

Read-Write DupCursor type
§

fn append<T>( &self, key: <T as Table>::Key, value: <T as Table>::Value, ) -> Result<(), DatabaseError>
where T: Table,

Append value with the largest key to database. This should have the same outcome as put, but databases like MDBX provide dedicated modes to make it much faster, typically from O(logN) down to O(1) thanks to no lookup.
§

impl Debug for TxMock

§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
§

impl Default for TxMock

§

fn default() -> TxMock

Returns the “default value” for a type. Read more
§

impl TableImporter for TxMock

§

fn import_table<T, R>(&self, source_tx: &R) -> Result<(), DatabaseError>
where T: Table, R: DbTx,

Imports all table data from another transaction.
§

fn import_table_with_range<T, R>( &self, source_tx: &R, from: Option<<T as Table>::Key>, to: <T as Table>::Key, ) -> Result<(), DatabaseError>
where T: Table, R: DbTx, <T as Table>::Key: Default,

Imports table data from another transaction within a range. Read more
§

fn import_dupsort<T, R>(&self, source_tx: &R) -> Result<(), DatabaseError>
where T: DupSort, R: DbTx,

Imports all dupsort data from another transaction.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit #126799)
Performs copy-assignment from self to dest. Read more
§

impl<T> DbTxUnwindExt for T
where T: DbTxMut,

§

fn unwind_table_by_num<T>(&self, num: u64) -> Result<usize, DatabaseError>
where T: Table<Key = u64>,

Unwind table by some number key. Returns number of rows unwound. Read more
§

fn unwind_table<T, F>( &self, key: u64, selector: F, ) -> Result<usize, DatabaseError>
where T: Table, F: FnMut(<T as Table>::Key) -> u64,

Unwind the table to a provided number key. Returns number of rows unwound. Read more
§

fn unwind_table_by_walker<T1, T2>( &self, range: impl RangeBounds<<T1 as Table>::Key>, ) -> Result<(), DatabaseError>
where T1: Table, T2: Table<Key = <T1 as Table>::Value>,

Unwind a table forward by a Walker on another table. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<T> MaybeDebug for T
where T: Debug,

§

impl<T> NonStaticAny for T
where T: ?Sized,

§

fn type_id(&self) -> TypeId

Returns the lifetime-erased type ID of self.
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more

Layout§

Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...) attributes. Please see the Rust Reference's “Type Layout” chapter for details on type layout guarantees.

Size: 24 bytes