pub struct FileContext { /* private fields */ }Expand description
The file transport’s per-delivery context: this delivery’s position in the stream file, and the subscription’s own seeker.
The runtime builds one per delivery, and handlers read its fields by key - Position and
SeekHandle. A handler that reads both, or that reads them on the manual path, names this
type as its context.
§Examples
use ruststream_sea_file::file::prelude::*;
use serde::Deserialize;
#[derive(Debug, Deserialize)]
struct Job {
id: u64,
}
#[subscriber(FileStream::new("jobs"))]
async fn work(job: &Job, ctx: &mut Context<'_, FileContext>) -> HandlerOutcome {
if job.id == 0 && ctx.context(SeekHandle).seek(FilePosition::end()).await.is_err() {
return HandlerOutcome::retry();
}
tracing::info!(job.id, position = ?ctx.context(Position), "worked");
HandlerOutcome::ack()
}
#[ruststream::app]
fn app() -> impl App {
RustStream::new(AppInfo::new("jobs", "0.1.0"))
.with_broker(FileBroker::new("/tmp/jobs.ss"), |b| {
b.include(work);
})
}Trait Implementations§
Source§impl BuildContext<FileMessage> for FileContext
impl BuildContext<FileMessage> for FileContext
Source§fn build(msg: &FileMessage) -> Self
fn build(msg: &FileMessage) -> Self
Builds the context value by reading fields out of
msg.Source§impl Debug for FileContext
impl Debug for FileContext
Source§impl Field<FileContext> for Position
impl Field<FileContext> for Position
Source§type Value<'a> = FilePosition
type Value<'a> = FilePosition
The value read through this key, borrowed from the source for
'a.Source§fn get(self, src: &FileContext) -> FilePosition
fn get(self, src: &FileContext) -> FilePosition
Reads this key’s field out of
src.Source§impl Field<FileContext> for SeekHandle
impl Field<FileContext> for SeekHandle
Source§type Value<'a> = &'a FileSeeker
type Value<'a> = &'a FileSeeker
The value read through this key, borrowed from the source for
'a.Source§fn get(self, src: &FileContext) -> &FileSeeker
fn get(self, src: &FileContext) -> &FileSeeker
Reads this key’s field out of
src.Auto Trait Implementations§
impl !RefUnwindSafe for FileContext
impl !UnwindSafe for FileContext
impl Freeze for FileContext
impl Send for FileContext
impl Sync for FileContext
impl Unpin for FileContext
impl UnsafeUnpin for FileContext
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
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> 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> ⓘ
Converts
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> ⓘ
Converts
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 more