Struct nats::kv::Store

source ·
pub struct Store { /* private fields */ }
Available on crate feature unstable only.
Expand description

A key value store

Implementations§

source§

impl Store

source

pub fn status(&self) -> Result<BucketStatus>

Returns the status of the bucket

source

pub fn entry(&self, key: &str) -> Result<Option<Entry>>

Returns the latest entry for the key, if any.

§Examples
bucket.put("foo", b"bar")?;
let maybe_entry = bucket.entry("foo")?;
if let Some(entry) = maybe_entry {
    println!("Found entry {:?}", entry);
}
source

pub fn get(&self, key: &str) -> Result<Option<Vec<u8>>>

Returns the latest value for the key, if any.

§Examples
bucket.put("foo", b"bar")?;
let maybe_value = bucket.get("foo")?;
if let Some(value) = maybe_value {
    println!("Found value {:?}", value);
}
source

pub fn put(&self, key: &str, value: impl AsRef<[u8]>) -> Result<u64>

Places the new value for the key into the bucket.

§Examples
bucket.put("foo", b"bar")?;
source

pub fn create(&self, key: &str, value: impl AsRef<[u8]>) -> Result<u64>

Creates the key/value pair if it does not exist or is marked for deletion.

§Examples
bucket.purge("foo")?;
bucket.create("foo", b"bar")?;
source

pub fn update( &self, key: &str, value: impl AsRef<[u8]>, revision: u64 ) -> Result<u64>

Updates the value if the latest revision matches.

§Examples
let revision = bucket.put("foo", b"bar")?;
let new_revision = bucket.update("foo", b"baz", revision)?;
source

pub fn delete(&self, key: &str) -> Result<()>

Marks an entry as deleted by placing a delete marker but leaves the revision history intact.

§Examples
bucket.create("foo", b"bar")?;
bucket.delete("foo")?;
source

pub fn purge(&self, key: &str) -> Result<()>

Remove any entries associated with the key and all historical revisions.

§Examples
bucket.create("foo", b"bar")?;
bucket.purge("foo")?;
source

pub fn keys(&self) -> Result<Keys>

Returns an iterator which iterate over all the current keys.

§Examples
bucket.put("foo", b"fizz")?;
bucket.put("bar", b"buzz")?;

let mut keys = bucket.keys()?;

assert_eq!(keys.next(), Some("foo".to_string()));
assert_eq!(keys.next(), Some("bar".to_string()));
source

pub fn history(&self, key: &str) -> Result<History>

Returns an iterator which iterates over each entry in historical order.

§Examples
let bucket = context.create_key_value(&Config {
    bucket: "history_iter".to_string(),
    history: 2,
    ..Default::default()
})?;

bucket.put("foo", b"fizz")?;
bucket.put("foo", b"buzz")?;

let mut history = bucket.history("foo")?;

let next = history.next().unwrap();
assert_eq!(next.key, "foo".to_string());
assert_eq!(next.value, b"fizz");

let next = history.next().unwrap();
assert_eq!(next.key, "foo".to_string());
assert_eq!(next.value, b"buzz");
source

pub fn watch_all(&self) -> Result<Watch>

Returns an iterator which iterates over each entry as they happen.

source

pub fn watch<T: AsRef<str>>(&self, key: T) -> Result<Watch>

Returns an iterator which iterates over each entry for specific key pattern as they happen.

source

pub fn bucket(&self) -> &String

Returns the name of the bucket

Trait Implementations§

source§

impl Clone for Store

source§

fn clone(&self) -> Store

Returns a copy of the value. Read more
1.0.0 · source§

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

Performs copy-assignment from source. Read more
source§

impl Debug for Store

source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Store

§

impl !RefUnwindSafe for Store

§

impl Send for Store

§

impl Sync for Store

§

impl Unpin for Store

§

impl !UnwindSafe for Store

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> Same for T

§

type Output = T

Should always be Self
source§

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

§

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

§

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

§

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<V, T> VZip<V> for T
where V: MultiLane<T>,

source§

fn vzip(self) -> V

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