Struct async_nats::jetstream::object_store::ObjectStore
source · pub struct ObjectStore { /* private fields */ }
Expand description
A blob store capable of storing large objects efficiently in streams.
Implementations§
source§impl ObjectStore
impl ObjectStore
sourcepub async fn get<T: AsRef<str>>(
&self,
object_name: T
) -> Result<Object<'_>, Error>
pub async fn get<T: AsRef<str>>( &self, object_name: T ) -> Result<Object<'_>, Error>
Gets an Object from the ObjectStore.
Object implements tokio::io::AsyncRead that allows to read the data from Object Store.
Examples
use tokio::io::AsyncReadExt;
let client = async_nats::connect("demo.nats.io").await?;
let jetstream = async_nats::jetstream::new(client);
let bucket = jetstream.get_object_store("store").await?;
let mut object = bucket.get("FOO").await?;
// Object implements `tokio::io::AsyncRead`.
let mut bytes = vec![];
object.read_to_end(&mut bytes).await?;
sourcepub async fn delete<T: AsRef<str>>(&self, object_name: T) -> Result<(), Error>
pub async fn delete<T: AsRef<str>>(&self, object_name: T) -> Result<(), Error>
Gets an Object from the ObjectStore.
Object implements tokio::io::AsyncRead that allows to read the data from Object Store.
Examples
let client = async_nats::connect("demo.nats.io").await?;
let jetstream = async_nats::jetstream::new(client);
let bucket = jetstream.get_object_store("store").await?;
bucket.delete("FOO").await?;
sourcepub async fn info<T: AsRef<str>>(
&self,
object_name: T
) -> Result<ObjectInfo, Error>
pub async fn info<T: AsRef<str>>( &self, object_name: T ) -> Result<ObjectInfo, Error>
Retrieves Object ObjectInfo.
Examples
let client = async_nats::connect("demo.nats.io").await?;
let jetstream = async_nats::jetstream::new(client);
let bucket = jetstream.get_object_store("store").await?;
let info = bucket.info("FOO").await?;
sourcepub async fn put<T>(
&self,
meta: T,
data: &mut impl AsyncRead + Unpin
) -> Result<ObjectInfo, Error>where
ObjectMeta: From<T>,
pub async fn put<T>( &self, meta: T, data: &mut impl AsyncRead + Unpin ) -> Result<ObjectInfo, Error>where ObjectMeta: From<T>,
Puts an Object into the ObjectStore.
This method implements tokio::io::AsyncRead
.
Examples
let client = async_nats::connect("demo.nats.io").await?;
let jetstream = async_nats::jetstream::new(client);
let bucket = jetstream.get_object_store("store").await?;
let mut file = tokio::fs::File::open("foo.txt").await?;
bucket.put("file", &mut file).await.unwrap();
sourcepub async fn watch(&self) -> Result<Watch<'_>, Error>
pub async fn watch(&self) -> Result<Watch<'_>, Error>
Creates a Watch stream over changes in the ObjectStore.
Examples
use futures::StreamExt;
let client = async_nats::connect("demo.nats.io").await?;
let jetstream = async_nats::jetstream::new(client);
let bucket = jetstream.get_object_store("store").await?;
let mut watcher = bucket.watch().await.unwrap();
while let Some(object) = watcher.next().await {
println!("detected changes in {:?}", object?);
}
sourcepub async fn list(&self) -> Result<List<'_>, Error>
pub async fn list(&self) -> Result<List<'_>, Error>
Returns a List stream with all not deleted Objects in the ObjectStore.
Examples
use futures::StreamExt;
let client = async_nats::connect("demo.nats.io").await?;
let jetstream = async_nats::jetstream::new(client);
let bucket = jetstream.get_object_store("store").await?;
let mut list = bucket.list().await.unwrap();
while let Some(object) = list.next().await {
println!("object {:?}", object?);
}
sourcepub async fn seal(&mut self) -> Result<(), Error>
pub async fn seal(&mut self) -> Result<(), Error>
Seals a ObjectStore, preventing any further changes to it or its Objects.
Examples
use futures::StreamExt;
let client = async_nats::connect("demo.nats.io").await?;
let jetstream = async_nats::jetstream::new(client);
let mut bucket = jetstream.get_object_store("store").await?;
bucket.seal().await.unwrap();
Trait Implementations§
source§impl Clone for ObjectStore
impl Clone for ObjectStore
source§fn clone(&self) -> ObjectStore
fn clone(&self) -> ObjectStore
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read more