pub struct Txn {
batch: WriteBatch,
engine: Arc<Engine>,
}Expand description
Atomic write batch spanning one or more column families from one database.
Every queued map must belong to the captured engine because column family identifiers are interpreted within that database. Dropping an unexecuted transaction leaves the database unchanged.
Fields§
§batch: WriteBatch§engine: Arc<Engine>Implementations§
Source§impl Txn
impl Txn
Sourcepub fn new(engine: &Arc<Engine>) -> Self
pub fn new(engine: &Arc<Engine>) -> Self
Creates an empty transaction for one database engine.
Operations can be appended through the typed or raw queueing methods. The
transaction remains inert until Txn::execute consumes it.
Source§impl Txn
impl Txn
Sourcepub fn with_capacity_bytes(engine: &Arc<Engine>, capacity_bytes: usize) -> Self
pub fn with_capacity_bytes(engine: &Arc<Engine>, capacity_bytes: usize) -> Self
Creates an empty transaction with reserved batch capacity.
capacity_bytes reserves storage for the serialized RocksDB batch
representation. The reservation affects allocation only and does not queue
an operation.
Source§impl Txn
impl Txn
Source§impl Txn
impl Txn
Sourcepub fn insert_slice<K, V>(map: &Map, items: &[(K, V)]) -> Self
pub fn insert_slice<K, V>(map: &Map, items: &[(K, V)]) -> Self
Queues a raw slice for one map with a precomputed capacity estimate.
The estimate includes payload lengths and worst-case record overhead before the items are copied into the write batch. Empty input produces an empty transaction.
Source§impl Txn
impl Txn
Sourcepub fn insert_each<'a, I, K, V>(items: I) -> Self
pub fn insert_each<'a, I, K, V>(items: I) -> Self
Queues raw entries across maps from a nonempty single pass.
The first item selects the database engine, and every subsequent map must belong to that same engine. The database codec is not applied to keys or values.
§Panics
Panics when items is empty or when any map belongs to a different database
engine.
Source§impl Txn
impl Txn
Sourcepub fn insert_each_slice<K, V>(items: &[(&Map, K, V)]) -> Self
pub fn insert_each_slice<K, V>(items: &[(&Map, K, V)]) -> Self
Queues a nonempty raw slice across maps with a capacity estimate.
The first item selects the database engine, and every map must belong to that same engine. The database codec is not applied to keys or values.
§Panics
Panics when items is empty or when any map belongs to a different database
engine.
Source§impl Txn
impl Txn
Sourcepub fn put_each<'a, I, K, V>(items: I) -> Self
pub fn put_each<'a, I, K, V>(items: I) -> Self
Serializes and queues entries across maps from a nonempty pass.
The first item selects the database engine, and every map must belong to that same engine. All keys and values are encoded with the database record codec before being copied into the batch.
§Panics
Panics when items is empty, a map belongs to another database engine, or
serialization of a key or value fails.
Source§impl Txn
impl Txn
Sourcepub fn put<K, V>(&mut self, map: &Map, key: K, val: V)
pub fn put<K, V>(&mut self, map: &Map, key: K, val: V)
Serializes and queues one insertion.
The key and value use the database record codec, and the operation remains
pending until Txn::execute. The map must belong to the transaction’s
database engine.
§Panics
Panics when the map belongs to another database engine or serialization of the key or value fails.
Source§impl Txn
impl Txn
Sourcepub fn put_raw<K, V>(&mut self, map: &Map, key: K, val: V)
pub fn put_raw<K, V>(&mut self, map: &Map, key: K, val: V)
Serializes the key and queues one raw-value insertion.
The key uses the database record codec, while the value bytes are copied
unchanged into the batch. The operation remains pending until
Txn::execute, and the map must belong to the transaction’s database
engine.
§Panics
Panics when the map belongs to another database engine or serialization of the key fails.
Source§impl Txn
impl Txn
Sourcepub fn raw_put<K, V>(&mut self, map: &Map, key: K, val: V)
pub fn raw_put<K, V>(&mut self, map: &Map, key: K, val: V)
Queues one raw-key insertion after serializing the value.
The key bytes are copied unchanged into the batch, while the value uses the
database record codec. The operation remains pending until Txn::execute,
and the map must belong to the transaction’s database engine.
§Panics
Panics when the map belongs to another database engine or serialization of the value fails.
Source§impl Txn
impl Txn
Sourcepub fn del<K>(&mut self, map: &Map, key: K)
pub fn del<K>(&mut self, map: &Map, key: K)
Serializes and queues one deletion.
The key uses the database record codec, and the operation remains pending
until Txn::execute. The map must belong to the transaction’s database
engine.
§Panics
Panics when the map belongs to another database engine or serialization of the key fails.
Source§impl Txn
impl Txn
Sourcepub fn del_raw<K>(&mut self, map: &Map, key: K)
pub fn del_raw<K>(&mut self, map: &Map, key: K)
Queues one deletion for an already serialized key.
The key bytes are copied into the write batch without invoking the database codec. The map must belong to the transaction’s database engine.
§Panics
Panics when the map belongs to another database engine.
Source§impl Txn
impl Txn
Sourcepub fn execute(self)
pub fn execute(self)
Commits the batch atomically, flushes unless corked, and notifies matching watchers.
An empty transaction returns without touching the engine. For a nonempty batch, notifications occur only after the write and any required flush succeed.
§Panics
Panics when RocksDB rejects the batch write or when the required database flush fails.
Source§impl Txn
impl Txn
Sourcepub fn keys(&self) -> impl Iterator<Item = (Arc<Map>, &[u8])> + '_
pub fn keys(&self) -> impl Iterator<Item = (Arc<Map>, &[u8])> + '_
Iterate queued put and delete keys in insertion order.
The iterator borrows keys directly from the serialized write batch without materializing a container. Keys whose column families are outside the startup map catalog are omitted.
§Panics
Iteration panics if a record has an unsupported operation tag, is truncated, or contains a varint whose fifth byte retains its continuation bit.
Source§impl Txn
impl Txn
Sourcepub fn size_in_bytes(&self) -> usize
pub fn size_in_bytes(&self) -> usize
Returns the encoded size of the RocksDB write batch in bytes.
The size includes batch metadata and queued record data. Inspecting it does not execute the transaction.
Source§impl Txn
impl Txn
Sourcepub fn insert_raw<K, V>(&mut self, map: &Map, key: K, val: V)
pub fn insert_raw<K, V>(&mut self, map: &Map, key: K, val: V)
Queue one unencoded key and value after enforcing map ownership.
Both byte sequences are copied into the write batch without invoking the
database codec. The operation remains pending until Txn::execute.
§Panics
Panics when the map belongs to another database engine.
Source§impl Txn
impl Txn
Sourcefn assert_map(&self, map: &Map)
fn assert_map(&self, map: &Map)
Verifies that a map belongs to the transaction’s database engine.
RocksDB identifies column families numerically within one database, so accepting a foreign map could target a same-numbered column family in the captured engine.
§Panics
Panics when map belongs to a different database engine.
Trait Implementations§
Source§impl<'a, K> Extend<(&'a Map, K)> for Txn
Extends this transaction with raw-key deletions across maps.
impl<'a, K> Extend<(&'a Map, K)> for Txn
Extends this transaction with raw-key deletions across maps.
Each tuple queues its raw key through Txn::del_raw. Every map must
belong to the transaction’s database engine.
§Panics
Panics when any map belongs to another database engine.
Source§fn extend<I>(&mut self, items: I)where
I: IntoIterator<Item = (&'a Map, K)>,
fn extend<I>(&mut self, items: I)where
I: IntoIterator<Item = (&'a Map, K)>,
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one)Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one)Source§impl<'a, K, V> Extend<(&'a Map, K, V)> for Txn
Extends this transaction with raw insertions across maps.
impl<'a, K, V> Extend<(&'a Map, K, V)> for Txn
Extends this transaction with raw insertions across maps.
Each tuple queues its raw key and value through Txn::insert_raw. Use
Txn::put_each when the keys and values need serialization. Every map
must belong to the transaction’s database engine.
§Panics
Panics when any map belongs to another database engine.
Source§fn extend<I>(&mut self, items: I)where
I: IntoIterator<Item = (&'a Map, K, V)>,
fn extend<I>(&mut self, items: I)where
I: IntoIterator<Item = (&'a Map, K, V)>,
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one)Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one)Auto Trait Implementations§
impl !RefUnwindSafe for Txn
impl !Sync for Txn
impl !UnwindSafe for Txn
impl Freeze for Txn
impl Send for Txn
impl Unpin for Txn
impl UnsafeUnpin for Txn
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> ExpectInto for T
impl<T> ExpectInto for T
Source§impl<T> Expected for T
impl<T> Expected for T
Source§fn expected_add(self, rhs: Self) -> Selfwhere
Self: Sized + CheckedAdd,
fn expected_add(self, rhs: Self) -> Selfwhere
Self: Sized + CheckedAdd,
rhs with an expectation that the operation is valid. Read moreSource§fn expected_sub(self, rhs: Self) -> Selfwhere
Self: Sized + CheckedSub,
fn expected_sub(self, rhs: Self) -> Selfwhere
Self: Sized + CheckedSub,
rhs with an expectation that the operation is valid. Read moreSource§fn expected_mul(self, rhs: Self) -> Selfwhere
Self: Sized + CheckedMul,
fn expected_mul(self, rhs: Self) -> Selfwhere
Self: Sized + CheckedMul,
rhs with an expectation that the operation is valid. Read moreSource§fn expected_div(self, rhs: Self) -> Selfwhere
Self: Sized + CheckedDiv,
fn expected_div(self, rhs: Self) -> Selfwhere
Self: Sized + CheckedDiv,
rhs with an expectation that the operation is valid. Read moreSource§fn expected_rem(self, rhs: Self) -> Selfwhere
Self: Sized + CheckedRem,
fn expected_rem(self, rhs: Self) -> Selfwhere
Self: Sized + CheckedRem,
§impl<T> Identity for Twhere
T: ?Sized,
impl<T> Identity for Twhere
T: ?Sized,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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 moreimpl<T> JsonCastable<CanonicalJsonValue> for T
impl<T> JsonCastable<Value> for T
§impl<T> Paint for Twhere
T: ?Sized,
impl<T> Paint for Twhere
T: ?Sized,
§fn fg(&self, value: Color) -> Painted<&T>
fn fg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the foreground set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like red() and
green(), which have the same functionality but are
pithier.
§Example
Set foreground color to white using fg():
use yansi::{Paint, Color};
painted.fg(Color::White);Set foreground color to white using white().
use yansi::Paint;
painted.white();§fn bright_black(&self) -> Painted<&T>
fn bright_black(&self) -> Painted<&T>
§fn bright_red(&self) -> Painted<&T>
fn bright_red(&self) -> Painted<&T>
§fn bright_green(&self) -> Painted<&T>
fn bright_green(&self) -> Painted<&T>
§fn bright_yellow(&self) -> Painted<&T>
fn bright_yellow(&self) -> Painted<&T>
§fn bright_blue(&self) -> Painted<&T>
fn bright_blue(&self) -> Painted<&T>
§fn bright_magenta(&self) -> Painted<&T>
fn bright_magenta(&self) -> Painted<&T>
§fn bright_cyan(&self) -> Painted<&T>
fn bright_cyan(&self) -> Painted<&T>
§fn bright_white(&self) -> Painted<&T>
fn bright_white(&self) -> Painted<&T>
§fn bg(&self, value: Color) -> Painted<&T>
fn bg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the background set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like on_red() and
on_green(), which have the same functionality but
are pithier.
§Example
Set background color to red using fg():
use yansi::{Paint, Color};
painted.bg(Color::Red);Set background color to red using on_red().
use yansi::Paint;
painted.on_red();§fn on_primary(&self) -> Painted<&T>
fn on_primary(&self) -> Painted<&T>
§fn on_magenta(&self) -> Painted<&T>
fn on_magenta(&self) -> Painted<&T>
§fn on_bright_black(&self) -> Painted<&T>
fn on_bright_black(&self) -> Painted<&T>
§fn on_bright_red(&self) -> Painted<&T>
fn on_bright_red(&self) -> Painted<&T>
§fn on_bright_green(&self) -> Painted<&T>
fn on_bright_green(&self) -> Painted<&T>
§fn on_bright_yellow(&self) -> Painted<&T>
fn on_bright_yellow(&self) -> Painted<&T>
§fn on_bright_blue(&self) -> Painted<&T>
fn on_bright_blue(&self) -> Painted<&T>
§fn on_bright_magenta(&self) -> Painted<&T>
fn on_bright_magenta(&self) -> Painted<&T>
§fn on_bright_cyan(&self) -> Painted<&T>
fn on_bright_cyan(&self) -> Painted<&T>
§fn on_bright_white(&self) -> Painted<&T>
fn on_bright_white(&self) -> Painted<&T>
§fn attr(&self, value: Attribute) -> Painted<&T>
fn attr(&self, value: Attribute) -> Painted<&T>
Enables the styling [Attribute] value.
This method should be used rarely. Instead, prefer to use
attribute-specific builder methods like bold() and
underline(), which have the same functionality
but are pithier.
§Example
Make text bold using attr():
use yansi::{Paint, Attribute};
painted.attr(Attribute::Bold);Make text bold using using bold().
use yansi::Paint;
painted.bold();§fn rapid_blink(&self) -> Painted<&T>
fn rapid_blink(&self) -> Painted<&T>
§fn quirk(&self, value: Quirk) -> Painted<&T>
fn quirk(&self, value: Quirk) -> Painted<&T>
Enables the yansi [Quirk] value.
This method should be used rarely. Instead, prefer to use quirk-specific
builder methods like mask() and
wrap(), which have the same functionality but are
pithier.
§Example
Enable wrapping using .quirk():
use yansi::{Paint, Quirk};
painted.quirk(Quirk::Wrap);Enable wrapping using wrap().
use yansi::Paint;
painted.wrap();§fn clear(&self) -> Painted<&T>
👎Deprecated since 1.0.1: renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
fn clear(&self) -> Painted<&T>
renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
§fn whenever(&self, value: Condition) -> Painted<&T>
fn whenever(&self, value: Condition) -> Painted<&T>
Conditionally enable styling based on whether the [Condition] value
applies. Replaces any previous condition.
See the crate level docs for more details.
§Example
Enable styling painted only when both stdout and stderr are TTYs:
use yansi::{Paint, Condition};
painted.red().on_yellow().whenever(Condition::STDOUTERR_ARE_TTY);§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
§impl<T> ServiceExt for T
impl<T> ServiceExt for T
§fn add_extension<T>(self, value: T) -> AddExtension<Self, T>where
Self: Sized,
fn add_extension<T>(self, value: T) -> AddExtension<Self, T>where
Self: Sized,
§fn compression(self) -> Compression<Self>where
Self: Sized,
fn compression(self) -> Compression<Self>where
Self: Sized,
§fn decompression(self) -> Decompression<Self>where
Self: Sized,
fn decompression(self) -> Decompression<Self>where
Self: Sized,
§fn trace_for_http(self) -> Trace<Self, SharedClassifier<ServerErrorsAsFailures>>where
Self: Sized,
fn trace_for_http(self) -> Trace<Self, SharedClassifier<ServerErrorsAsFailures>>where
Self: Sized,
§fn trace_for_grpc(self) -> Trace<Self, SharedClassifier<GrpcErrorsAsFailures>>where
Self: Sized,
fn trace_for_grpc(self) -> Trace<Self, SharedClassifier<GrpcErrorsAsFailures>>where
Self: Sized,
§fn follow_redirects(self) -> FollowRedirect<Self>where
Self: Sized,
fn follow_redirects(self) -> FollowRedirect<Self>where
Self: Sized,
§fn sensitive_headers(
self,
headers: impl IntoIterator<Item = HeaderName>,
) -> SetSensitiveRequestHeaders<SetSensitiveResponseHeaders<Self>>where
Self: Sized,
fn sensitive_headers(
self,
headers: impl IntoIterator<Item = HeaderName>,
) -> SetSensitiveRequestHeaders<SetSensitiveResponseHeaders<Self>>where
Self: Sized,
§fn sensitive_request_headers(
self,
headers: impl IntoIterator<Item = HeaderName>,
) -> SetSensitiveRequestHeaders<Self>where
Self: Sized,
fn sensitive_request_headers(
self,
headers: impl IntoIterator<Item = HeaderName>,
) -> SetSensitiveRequestHeaders<Self>where
Self: Sized,
§fn sensitive_response_headers(
self,
headers: impl IntoIterator<Item = HeaderName>,
) -> SetSensitiveResponseHeaders<Self>where
Self: Sized,
fn sensitive_response_headers(
self,
headers: impl IntoIterator<Item = HeaderName>,
) -> SetSensitiveResponseHeaders<Self>where
Self: Sized,
§fn override_request_header<M>(
self,
header_name: HeaderName,
make: M,
) -> SetRequestHeader<Self, M>where
Self: Sized,
fn override_request_header<M>(
self,
header_name: HeaderName,
make: M,
) -> SetRequestHeader<Self, M>where
Self: Sized,
§fn append_request_header<M>(
self,
header_name: HeaderName,
make: M,
) -> SetRequestHeader<Self, M>where
Self: Sized,
fn append_request_header<M>(
self,
header_name: HeaderName,
make: M,
) -> SetRequestHeader<Self, M>where
Self: Sized,
§fn insert_request_header_if_not_present<M>(
self,
header_name: HeaderName,
make: M,
) -> SetRequestHeader<Self, M>where
Self: Sized,
fn insert_request_header_if_not_present<M>(
self,
header_name: HeaderName,
make: M,
) -> SetRequestHeader<Self, M>where
Self: Sized,
§fn override_response_header<M>(
self,
header_name: HeaderName,
make: M,
) -> SetResponseHeader<Self, M>where
Self: Sized,
fn override_response_header<M>(
self,
header_name: HeaderName,
make: M,
) -> SetResponseHeader<Self, M>where
Self: Sized,
§fn append_response_header<M>(
self,
header_name: HeaderName,
make: M,
) -> SetResponseHeader<Self, M>where
Self: Sized,
fn append_response_header<M>(
self,
header_name: HeaderName,
make: M,
) -> SetResponseHeader<Self, M>where
Self: Sized,
§fn insert_response_header_if_not_present<M>(
self,
header_name: HeaderName,
make: M,
) -> SetResponseHeader<Self, M>where
Self: Sized,
fn insert_response_header_if_not_present<M>(
self,
header_name: HeaderName,
make: M,
) -> SetResponseHeader<Self, M>where
Self: Sized,
§fn catch_panic(self) -> CatchPanic<Self, DefaultResponseForPanic>where
Self: Sized,
fn catch_panic(self) -> CatchPanic<Self, DefaultResponseForPanic>where
Self: Sized,
500 Internal Server responses. Read moreSource§impl<T> Tried for T
impl<T> Tried for T
Source§fn try_add(self, rhs: Self) -> Result<Self, Error>where
Self: Sized + CheckedAdd,
fn try_add(self, rhs: Self) -> Result<Self, Error>where
Self: Sized + CheckedAdd,
rhs with checked arithmetic. Read moreSource§fn try_sub(self, rhs: Self) -> Result<Self, Error>where
Self: Sized + CheckedSub,
fn try_sub(self, rhs: Self) -> Result<Self, Error>where
Self: Sized + CheckedSub,
rhs with checked arithmetic. Read moreSource§fn try_mul(self, rhs: Self) -> Result<Self, Error>where
Self: Sized + CheckedMul,
fn try_mul(self, rhs: Self) -> Result<Self, Error>where
Self: Sized + CheckedMul,
rhs with checked arithmetic. Read more