Struct pravega_client::index::IndexWriter
source · pub struct IndexWriter<T: Fields + PartialOrd + PartialEq + Debug> { /* private fields */ }
Expand description
Index Writer writes a fixed size Record to the stream.
Write takes a byte array as data and Fields. It hashes each Field name and construct a Record. Then it serializes the Record and writes to the stream.
§Examples
use pravega_client_config::ClientConfigBuilder;
use pravega_client::client_factory::ClientFactory;
use pravega_client_shared::ScopedStream;
use pravega_client_macros::Fields;
use std::io::Write;
use tokio;
#[derive(Fields, Debug, PartialOrd, PartialEq)]
struct MyFields {
id: u64,
timestamp: u64,
}
#[tokio::main]
async fn main() {
// assuming Pravega controller is running at endpoint `localhost:9090`
let config = ClientConfigBuilder::default()
.controller_uri("localhost:9090")
.build()
.expect("creating config");
let client_factory = ClientFactory::new(config);
// assuming scope:myscope, stream:mystream exist.
// notice that this stream should be a fixed sized single segment stream
let stream = ScopedStream::from("myscope/mystream");
let mut index_writer = client_factory.create_index_writer(stream).await;
let fields = MyFields{id: 1, timestamp: 1000};
let data = vec!{1; 10};
index_writer.append(fields, data).await.expect("append data with fields");
index_writer.flush().await.expect("flush");
}
Implementations§
source§impl<T: Fields + PartialOrd + PartialEq + Debug> IndexWriter<T>
impl<T: Fields + PartialOrd + PartialEq + Debug> IndexWriter<T>
sourcepub async fn append(
&mut self,
fields: T,
data: Vec<u8>
) -> Result<(), IndexWriterError>
pub async fn append( &mut self, fields: T, data: Vec<u8> ) -> Result<(), IndexWriterError>
Append data with a given Fields.
sourcepub async fn append_conditionally(
&mut self,
fields: T,
condition_on: T,
data: Vec<u8>
) -> Result<(), IndexWriterError>
pub async fn append_conditionally( &mut self, fields: T, condition_on: T, data: Vec<u8> ) -> Result<(), IndexWriterError>
Append data with a given Fields and conditioned on a Fields. The conditional Fields should match the latest Fields in the stream, if not, this method will fail with error.
sourcepub async fn flush(&mut self) -> Result<(), IndexWriterError>
pub async fn flush(&mut self) -> Result<(), IndexWriterError>
Flush data.
Auto Trait Implementations§
impl<T> !Freeze for IndexWriter<T>
impl<T> !RefUnwindSafe for IndexWriter<T>
impl<T> Send for IndexWriter<T>where
T: Send,
impl<T> Sync for IndexWriter<T>where
T: Sync,
impl<T> Unpin for IndexWriter<T>where
T: Unpin,
impl<T> !UnwindSafe for IndexWriter<T>
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
Mutably borrows from an owned value. Read more
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
Wrap the input message
T
in a tonic::Request