Struct LinesCodec
struct LinesCodec { ... }
A simple Decoder and Encoder implementation that splits up data into lines.
This uses the \n character as the line ending on all platforms.
Implementations
impl LinesCodec
fn new() -> LinesCodecReturns a
LinesCodecfor splitting up data into lines.Note
The returned
LinesCodecwill not have an upper bound on the length of a buffered line. See the documentation fornew_with_max_lengthfor information on why this could be a potential security risk.fn new_with_max_length(max_length: usize) -> SelfReturns a
LinesCodecwith a maximum line length limit.If this is set, calls to
LinesCodec::decodewill return aLinesCodecErrorwhen a line exceeds the length limit. Subsequent calls will discard up tolimitbytes from that line until a newline character is reached, returningNoneuntil the line 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
LinesCodecwhich will be exposed to untrusted input. Otherwise, the size of the buffer that holds the line currently being read is unbounded. An attacker could exploit this unbounded buffer by sending an unbounded amount of input without any\ncharacters, causing unbounded memory consumption.fn max_length(self: &Self) -> usizeReturns the maximum line length when decoding.
use usize; use LinesCodec; let codec = new; assert_eq!;use LinesCodec; let codec = new_with_max_length; assert_eq!;
impl Clone for LinesCodec
fn clone(self: &Self) -> LinesCodec
impl Debug for LinesCodec
fn fmt(self: &Self, f: &mut Formatter<'_>) -> Result
impl Decoder for LinesCodec
fn decode(self: &mut Self, buf: &mut BytesMut) -> Result<Option<String>, LinesCodecError>fn decode_eof(self: &mut Self, buf: &mut BytesMut) -> Result<Option<String>, LinesCodecError>
impl Default for LinesCodec
fn default() -> Self
impl Eq for LinesCodec
impl Freeze for LinesCodec
impl Hash for LinesCodec
fn hash<__H: $crate::hash::Hasher>(self: &Self, state: &mut __H)
impl Ord for LinesCodec
fn cmp(self: &Self, other: &LinesCodec) -> Ordering
impl PartialEq for LinesCodec
fn eq(self: &Self, other: &LinesCodec) -> bool
impl PartialOrd for LinesCodec
fn partial_cmp(self: &Self, other: &LinesCodec) -> Option<Ordering>
impl RefUnwindSafe for LinesCodec
impl Send for LinesCodec
impl StructuralPartialEq for LinesCodec
impl Sync for LinesCodec
impl Unpin for LinesCodec
impl UnsafeUnpin for LinesCodec
impl UnwindSafe for LinesCodec
impl<T> Any for LinesCodec
fn type_id(self: &Self) -> TypeId
impl<T> Borrow for LinesCodec
fn borrow(self: &Self) -> &T
impl<T> BorrowMut for LinesCodec
fn borrow_mut(self: &mut Self) -> &mut T
impl<T> CloneToUninit for LinesCodec
unsafe fn clone_to_uninit(self: &Self, dest: *mut u8)
impl<T> Encoder for LinesCodec
fn encode(self: &mut Self, line: T, buf: &mut BytesMut) -> Result<(), LinesCodecError>
impl<T> From for LinesCodec
fn from(t: T) -> TReturns the argument unchanged.
impl<T> ToOwned for LinesCodec
fn to_owned(self: &Self) -> Tfn clone_into(self: &Self, target: &mut T)
impl<T, U> Into for LinesCodec
fn into(self: Self) -> UCalls
U::from(self).That is, this conversion is whatever the implementation of
[From]<T> for Uchooses to do.
impl<T, U> TryFrom for LinesCodec
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
impl<T, U> TryInto for LinesCodec
fn try_into(self: Self) -> Result<U, <U as TryFrom<T>>::Error>