Struct AnyDelimiterCodec
pub struct AnyDelimiterCodec { /* private fields */ }
A simple Decoder and Encoder implementation that splits up data into chunks based on any character in the given delimiter string.
Example
Decode string of bytes containing various different delimiters.
use ;
use ;
#
#
# async
Implementations
impl AnyDelimiterCodec
fn new(seek_delimiters: Vec<u8>, sequence_writer: Vec<u8>) -> AnyDelimiterCodecReturns a
AnyDelimiterCodecfor splitting up data into chunks.Note
The returned
AnyDelimiterCodecwill not have an upper bound on the length of a buffered chunk. See the documentation fornew_with_max_lengthfor information on why this could be a potential security risk.fn new_with_max_length(seek_delimiters: Vec<u8>, sequence_writer: Vec<u8>, max_length: usize) -> SelfReturns a
AnyDelimiterCodecwith a maximum chunk length limit.If this is set, calls to
AnyDelimiterCodec::decodewill return aAnyDelimiterCodecErrorwhen a chunk exceeds the length limit. Subsequent calls will discard up tolimitbytes from that chunk until a delimiter character is reached, returningNoneuntil the delimiter over the limit has been fully discarded. After that point, calls todecodewill function as normal.Note
Setting a length limit is highly recommended for any
AnyDelimiterCodecwhich will be exposed to untrusted input. Otherwise, the size of the buffer that holds the chunk currently being read is unbounded. An attacker could exploit this unbounded buffer by sending an unbounded amount of input without any delimiter characters, causing unbounded memory consumption.fn max_length(&self) -> usizeReturns the maximum chunk length when decoding.
use usize; use AnyDelimiterCodec; let codec = new; assert_eq!;use AnyDelimiterCodec; let codec = new_with_max_length; assert_eq!;
Trait Implementations
impl Clone for AnyDelimiterCodec
fn clone(&self) -> AnyDelimiterCodec
impl Debug for AnyDelimiterCodec
fn fmt(&self, f: &mut Formatter<'_>) -> Result
impl Decoder for AnyDelimiterCodec
type Item = Bytes;type Error = AnyDelimiterCodecError;fn decode(&mut self, buf: &mut BytesMut) -> Result<Option<Bytes>, AnyDelimiterCodecError>fn decode_eof(&mut self, buf: &mut BytesMut) -> Result<Option<Bytes>, AnyDelimiterCodecError>
impl Default for AnyDelimiterCodec
fn default() -> Self
impl Eq for AnyDelimiterCodec
impl Hash for AnyDelimiterCodec
fn hash<__H: Hasher>(&self, state: &mut __H)
impl Ord for AnyDelimiterCodec
fn cmp(&self, other: &AnyDelimiterCodec) -> Ordering
impl PartialEq for AnyDelimiterCodec
fn eq(&self, other: &AnyDelimiterCodec) -> bool
impl PartialOrd for AnyDelimiterCodec
fn partial_cmp(&self, other: &AnyDelimiterCodec) -> Option<Ordering>
impl StructuralPartialEq for AnyDelimiterCodec
impl<T> Encoder<T> for AnyDelimiterCodec
where
T: AsRef<str>,
type Error = AnyDelimiterCodecError;fn encode(&mut self, chunk: T, buf: &mut BytesMut) -> Result<(), AnyDelimiterCodecError>
Auto Trait Implementations
impl Freeze for AnyDelimiterCodec
impl RefUnwindSafe for AnyDelimiterCodec
impl Send for AnyDelimiterCodec
impl Sync for AnyDelimiterCodec
impl Unpin for AnyDelimiterCodec
impl UnsafeUnpin for AnyDelimiterCodec
impl UnwindSafe for AnyDelimiterCodec
Blanket Implementations
impl<T> Any for AnyDelimiterCodec
where
T: 'static + ?Sized,
fn type_id(&self) -> TypeId
impl<T> Borrow<T> for AnyDelimiterCodec
where
T: ?Sized,
fn borrow(&self) -> &T
impl<T> BorrowMut<T> for AnyDelimiterCodec
where
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
impl<T> CloneToUninit for AnyDelimiterCodec
where
T: Clone,
unsafe fn clone_to_uninit(&self, dest: *mut u8)
impl<T> From<T> for AnyDelimiterCodec
fn from(t: T) -> TReturns the argument unchanged.
impl<T> ToOwned for AnyDelimiterCodec
where
T: Clone,
type Owned = T;fn to_owned(&self) -> Tfn clone_into(&self, target: &mut T)
impl<T, U> Into<U> for AnyDelimiterCodec
where
U: From<T>,
fn into(self) -> UCalls
U::from(self).That is, this conversion is whatever the implementation of
[From]<T> for Uchooses to do.
impl<T, U> TryFrom<U> for AnyDelimiterCodec
where
U: Into<T>,
type Error = Infallible;fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
impl<T, U> TryInto<U> for AnyDelimiterCodec
where
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error;fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>