Trait StreamObserver

Source
pub trait StreamObserver {
    // Provided methods
    fn begin(&mut self) { ... }
    fn before_read(&mut self) -> ObserverDecision { ... }
    fn before_write(&mut self, _: &[u8]) -> ObserverDecision { ... }
    fn after_write(&mut self, _: &[u8]) -> ObserverDecision { ... }
    fn end(&mut self, _: usize, _: Option<Box<&dyn Error>>) { ... }
}
Expand description

Observe a stream’s operation when user code is not involved. For example: When you call EhRead.stream_to function, and you may want to calculate the checksum (SHA1, SHA256 or MD5 along the way, you can observe the stream copy using the observer)

Provided Methods§

Source

fn begin(&mut self)

Your observer’s begin will be called before stream copy If you plan to reuse the observer, you can reset it here

Source

fn before_read(&mut self) -> ObserverDecision

Before the upstream is read. If you want to abort, abort it here by overriding the before_read()

Source

fn before_write(&mut self, _: &[u8]) -> ObserverDecision

A chunk of data had been read from upstream, about to be written now You can intercept it by aborting it here

Source

fn after_write(&mut self, _: &[u8]) -> ObserverDecision

A chunk of data had been written to down stream. You can intercept it by aborting it here

Source

fn end(&mut self, _: usize, _: Option<Box<&dyn Error>>)

The copy ended and size bytes had been copied If there is error, err with be Some(cause) Note, different from Result<usize, Box>, the bytes copied is always given Even if it is zero

Implementors§