Struct LinesCodec
pub struct LinesCodec { /* private fields */ }
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) -> 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!;
Trait Implementations
impl Clone for LinesCodec
fn clone(&self) -> LinesCodec
impl Debug for LinesCodec
fn fmt(&self, f: &mut Formatter<'_>) -> Result
impl Decoder for LinesCodec
type Item = String;type Error = LinesCodecError;fn decode(&mut self, buf: &mut BytesMut) -> Result<Option<String>, LinesCodecError>fn decode_eof(&mut self, buf: &mut BytesMut) -> Result<Option<String>, LinesCodecError>
impl Default for LinesCodec
fn default() -> Self
impl Eq for LinesCodec
impl Hash for LinesCodec
fn hash<__H: Hasher>(&self, state: &mut __H)
impl Ord for LinesCodec
fn cmp(&self, other: &LinesCodec) -> Ordering
impl PartialEq for LinesCodec
fn eq(&self, other: &LinesCodec) -> bool
impl PartialOrd for LinesCodec
fn partial_cmp(&self, other: &LinesCodec) -> Option<Ordering>
impl StructuralPartialEq for LinesCodec
impl<T> Encoder<T> for LinesCodec
where
T: AsRef<str>,
type Error = LinesCodecError;fn encode(&mut self, line: T, buf: &mut BytesMut) -> Result<(), LinesCodecError>
Auto Trait Implementations
impl Freeze for LinesCodec
impl RefUnwindSafe for LinesCodec
impl Send for LinesCodec
impl Sync for LinesCodec
impl Unpin for LinesCodec
impl UnsafeUnpin for LinesCodec
impl UnwindSafe for LinesCodec
Blanket Implementations
impl<T> Any for LinesCodec
where
T: 'static + ?Sized,
fn type_id(&self) -> TypeId
impl<T> Borrow<T> for LinesCodec
where
T: ?Sized,
fn borrow(&self) -> &T
impl<T> BorrowMut<T> for LinesCodec
where
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
impl<T> CloneToUninit for LinesCodec
where
T: Clone,
unsafe fn clone_to_uninit(&self, dest: *mut u8)
impl<T> From<T> for LinesCodec
fn from(t: T) -> TReturns the argument unchanged.
impl<T> ToOwned for LinesCodec
where
T: Clone,
type Owned = T;fn to_owned(&self) -> Tfn clone_into(&self, target: &mut T)
impl<T, U> Into<U> for LinesCodec
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 LinesCodec
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 LinesCodec
where
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error;fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>