Skip to main content

TempDatabase

Struct TempDatabase 

Source
pub struct TempDatabase<DB> { /* private fields */ }
Available on crate features test-utils only.
Expand description

A database will delete the db dir when dropped.

Implementations§

Source§

impl<DB> TempDatabase<DB>

Source

pub fn new(db: DB, path: PathBuf) -> Self

Create new TempDatabase instance.

Source

pub const fn db(&self) -> &DB

Returns the reference to inner db.

Source

pub fn path(&self) -> &Path

Returns the path to the database.

Source

pub fn into_inner_db(self) -> DB

Convert temp database into inner.

Source

pub fn set_pre_transaction_hook(&self, hook: Box<dyn Fn() + Send + Sync>)

Sets TempDatabase new pre transaction creation hook.

Source

pub fn set_post_transaction_hook(&self, hook: Box<dyn Fn() + Send + Sync>)

Sets TempDatabase new post transaction creation hook.

Trait Implementations§

Source§

impl<DB: Database> Database for TempDatabase<DB>

Source§

type TX = <DB as Database>::TX

Read-Only database transaction
Source§

type TXMut = <DB as Database>::TXMut

Read-Write database transaction
Source§

fn tx(&self) -> Result<Self::TX, DatabaseError>

Create read only transaction.
Source§

fn tx_mut(&self) -> Result<Self::TXMut, DatabaseError>

Create read write transaction only possible if database is open with write access.
Source§

fn path(&self) -> PathBuf

Returns the path to the database directory.
Source§

fn oldest_reader_txnid(&self) -> Option<u64>

Returns the transaction ID of the oldest active reader, if available. Read more
Source§

fn last_txnid(&self) -> Option<u64>

Returns the ID of the most recently committed transaction, if available.
§

fn view<T, F>(&self, f: F) -> Result<T, DatabaseError>
where F: FnOnce(&mut Self::TX) -> T,

Takes a function and passes a read-only transaction into it, making sure it’s closed in the end of the execution.
§

fn update<T, F>(&self, f: F) -> Result<T, DatabaseError>
where F: FnOnce(&Self::TXMut) -> T,

Takes a function and passes a write-read transaction into it, making sure it’s committed in the end of the execution.
Source§

impl<DB: DatabaseMetrics> DatabaseMetrics for TempDatabase<DB>

Source§

fn report_metrics(&self)

Reports metrics for the database.
§

fn gauge_metrics(&self) -> Vec<(&'static str, f64, Vec<Label>)>

Returns a list of Gauge metrics for the database.
§

fn counter_metrics(&self) -> Vec<(&'static str, u64, Vec<Label>)>

Returns a list of Counter metrics for the database.
§

fn histogram_metrics(&self) -> Vec<(&'static str, f64, Vec<Label>)>

Returns a list of Histogram metrics for the database.
Source§

impl<DB: Debug> Debug for TempDatabase<DB>

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<DB> Drop for TempDatabase<DB>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics #130494)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

Auto Trait Implementations§

§

impl<DB> !Freeze for TempDatabase<DB>

§

impl<DB> !RefUnwindSafe for TempDatabase<DB>

§

impl<DB> !UnwindSafe for TempDatabase<DB>

§

impl<DB> Send for TempDatabase<DB>
where Option<DB>: Send,

§

impl<DB> Sync for TempDatabase<DB>
where Option<DB>: Sync,

§

impl<DB> Unpin for TempDatabase<DB>
where Option<DB>: Unpin,

§

impl<DB> UnsafeUnpin for TempDatabase<DB>
where Option<DB>: UnsafeUnpin,

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> 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,

§

impl<DB> ReaderTxnTracker for DB
where DB: Database,

§

fn wait_for_pre_commit_readers(&self)

Waits until all readers older than the latest committed txnid have drained.
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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: Unable to compute type layout, possibly due to this type having generic parameters. Layout can only be computed for concrete, fully-instantiated types.