pub struct DotStufferState { /* private fields */ }Expand description
Streaming version of the RFC 5321 dot-stuffer.
Unlike dot_stuff_and_terminate, this processes the message body
one chunk at a time, keeping memory usage at O(chunk size) rather than
O(body size). Suitable for large messages and memory-constrained runtimes.
§Usage
use wasm_smtp::protocol::DotStufferState;
let mut stuffer = DotStufferState::new();
// Process each chunk.
let chunk1 = b"Subject: test\r\n\r\n";
let out1 = stuffer.process_chunk(chunk1);
let chunk2 = b".dotted line\r\nend\r\n";
let out2 = stuffer.process_chunk(chunk2);
// Produce the end-of-data terminator.
let terminator = stuffer.finish();
// on-wire: out1 + out2 + terminator
assert_eq!(&out2[..2], b".."); // dot-stuffed
assert_eq!(terminator, b".\r\n");Implementations§
Source§impl DotStufferState
impl DotStufferState
Sourcepub fn process_chunk(&mut self, chunk: &[u8]) -> Vec<u8> ⓘ
pub fn process_chunk(&mut self, chunk: &[u8]) -> Vec<u8> ⓘ
Dot-stuff one chunk and return the processed bytes.
The returned Vec is slightly larger than chunk only when one or
more lines in the chunk begin with .. All other bytes pass through
unchanged.
process_chunk with an empty slice is a no-op and returns an empty
Vec.
§Cross-chunk dot-stuffing
The state machine correctly handles dots that appear at the start of
a line which spans two consecutive chunks. For example, if chunk N
ends with \r\n and chunk N+1 starts with ., the leading dot in
chunk N+1 will be stuffed.
Trait Implementations§
Source§impl Clone for DotStufferState
impl Clone for DotStufferState
Source§fn clone(&self) -> DotStufferState
fn clone(&self) -> DotStufferState
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for DotStufferState
impl Debug for DotStufferState
Auto Trait Implementations§
impl Freeze for DotStufferState
impl RefUnwindSafe for DotStufferState
impl Send for DotStufferState
impl Sync for DotStufferState
impl Unpin for DotStufferState
impl UnsafeUnpin for DotStufferState
impl UnwindSafe for DotStufferState
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