Skip to main content

Sequence

Struct Sequence 

Source
pub struct Sequence<'db> { /* private fields */ }
Expand description

A handle for manipulating a sequence record stored in a Database.

Multiple threads may share a single Sequence handle safely; all cache manipulation is protected by an internal Mutex. For higher throughput open separate handles to the same database key.

§Example

use noxu_db::{SequenceConfig, DatabaseEntry};

let config = SequenceConfig::new().with_allow_create(true);
let key = DatabaseEntry::from_bytes(b"my_counter");
let seq = db.open_sequence(&key, config).unwrap();

let v1 = seq.get(None, 1).unwrap();
let v2 = seq.get(None, 1).unwrap();
assert_eq!(v2, v1 + 1);

Implementations§

Source§

impl<'db> Sequence<'db>

Source

pub fn get(&self, txn: Option<&Transaction>, delta: i32) -> Result<i64>

Returns the next available element in the sequence and advances by delta.

delta must be > 0 and must fit within the configured range.

The txn parameter, if provided, is used for the cache-refill database write, making it participate in the caller’s transaction. Sequence.get(Transaction txn, int delta).

Source

pub fn get_stats(&self) -> SequenceStats

Returns a snapshot of statistics for this handle.

Source

pub fn close(&self) -> Result<()>

Closes the sequence handle.

After calling this method the handle must not be used again. Unused cached values are discarded.

Auto Trait Implementations§

§

impl<'db> !Freeze for Sequence<'db>

§

impl<'db> !RefUnwindSafe for Sequence<'db>

§

impl<'db> !UnwindSafe for Sequence<'db>

§

impl<'db> Send for Sequence<'db>

§

impl<'db> Sync for Sequence<'db>

§

impl<'db> Unpin for Sequence<'db>

§

impl<'db> UnsafeUnpin for Sequence<'db>

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
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

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

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

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.
Source§

impl<T> WithSubscriber for T

Source§

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
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

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