pub struct Sink { /* private fields */ }Expand description
A mock which can act as a data sink.
An instance of the mock can be constructed using the builder-style methods. Each item added by
the builder methods will be returned in-order when data is written to the Sink.
Data can then be written to it using the embedded_io::Write or embedded_io_async::Write
traits.
§Blocking Example
use embedded_io::Write;
let mut mock_sink = Sink::new()
.accept_data(12)
.error(MockError(embedded_io::ErrorKind::BrokenPipe));
let data_bytes = "hello world!".as_bytes();
let res = mock_sink.write_all(data_bytes);
assert!(res.is_ok());
let res = mock_sink.write(data_bytes);
assert!(res.is_err_and(|e| e == MockError(embedded_io::ErrorKind::BrokenPipe)));§Async Example
use embedded_io_async::Write;
let mut mock_sink = Sink::new()
.accept_data(12)
.error(MockError(embedded_io::ErrorKind::BrokenPipe));
let data_bytes = "hello world!".as_bytes();
let res = mock_sink.write_all(data_bytes).await;
assert!(res.is_ok());
let res = mock_sink.write(data_bytes).await;
assert!(res.is_err_and(|e| e == MockError(embedded_io::ErrorKind::BrokenPipe)));Implementations§
Source§impl Sink
impl Sink
Sourcepub fn accept_data(self, n: usize) -> Self
pub fn accept_data(self, n: usize) -> Self
Accept n bytes of data written to the Sink
Sourcepub fn is_consumed(&self) -> bool
pub fn is_consumed(&self) -> bool
Check if all of the provided items were consumed
Sourcepub fn into_inner_data(self) -> Vec<u8> ⓘ
pub fn into_inner_data(self) -> Vec<u8> ⓘ
Get the inner data that has been received from the writer
Sourcepub fn owned_handle(&mut self) -> OwnedHandle<'_, Self>
pub fn owned_handle(&mut self) -> OwnedHandle<'_, Self>
Get an OwnedHandle containing the Sink
Trait Implementations§
Source§impl Write for Sink
impl Write for Sink
Source§fn write(&mut self, buf: &[u8]) -> Result<usize, Self::Error>
fn write(&mut self, buf: &[u8]) -> Result<usize, Self::Error>
Write a buffer into this writer, returning how many bytes were written. Read more
Source§fn flush(&mut self) -> Result<(), Self::Error>
fn flush(&mut self) -> Result<(), Self::Error>
Flush this output stream, blocking until all intermediately buffered contents reach their destination.
Source§impl Write for Sink
impl Write for Sink
Source§async fn write(&mut self, buf: &[u8]) -> Result<usize, Self::Error>
async fn write(&mut self, buf: &[u8]) -> Result<usize, Self::Error>
Write a buffer into this writer, returning how many bytes were written. Read more
Auto Trait Implementations§
impl Freeze for Sink
impl RefUnwindSafe for Sink
impl Send for Sink
impl Sync for Sink
impl Unpin for Sink
impl UnwindSafe for Sink
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