pub struct StreamSource { /* private fields */ }Expand description
A data source that receives monitor snapshots from an async stream.
This source spawns a background task that reads newline-delimited JSON
from the provided async reader and makes snapshots available via poll().
§Example with a byte stream
use std::io::Cursor;
use buswatch_tui::StreamSource;
let data = b"{}\n";
let stream = Cursor::new(data.to_vec());
let source = StreamSource::spawn(stream, "example");Implementations§
Source§impl StreamSource
impl StreamSource
Sourcepub fn spawn<R>(reader: R, description: &str) -> Self
pub fn spawn<R>(reader: R, description: &str) -> Self
Spawn a background task that reads from the given async reader.
The reader should provide newline-delimited JSON snapshots.
Each line is parsed as a complete MonitorSnapshot.
Sourcepub fn from_bytes_channel(rx: Receiver<Vec<u8>>, description: &str) -> Self
pub fn from_bytes_channel(rx: Receiver<Vec<u8>>, description: &str) -> Self
Create a StreamSource from a raw bytes channel.
This is useful when you want to push JSON bytes from another source (like a message bus) without using an AsyncRead.
Each Vec<u8> sent through the channel should be a complete JSON snapshot.
Source§impl StreamSource
impl StreamSource
Sourcepub fn last_error(&self) -> Option<String>
pub fn last_error(&self) -> Option<String>
Get the last error message, if any.
Trait Implementations§
Source§impl DataSource for StreamSource
impl DataSource for StreamSource
Auto Trait Implementations§
impl Freeze for StreamSource
impl RefUnwindSafe for StreamSource
impl Send for StreamSource
impl Sync for StreamSource
impl Unpin for StreamSource
impl UnwindSafe for StreamSource
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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