pub struct LinesCodec { /* private fields */ }
codec
only.Expand description
Implementations§
Source§impl LinesCodec
impl LinesCodec
Sourcepub fn new() -> LinesCodec
pub fn new() -> LinesCodec
Returns a LinesCodec
for splitting up data into lines.
§Note
The returned LinesCodec
will not have an upper bound on the length
of a buffered line. See the documentation for new_with_max_length
for information on why this could be a potential security risk.
Sourcepub fn new_with_max_length(max_length: usize) -> Self
pub fn new_with_max_length(max_length: usize) -> Self
Returns a LinesCodec
with a maximum line length limit.
If this is set, calls to LinesCodec::decode
will return a
LinesCodecError
when a line exceeds the length limit. Subsequent calls
will discard up to limit
bytes from that line until a newline
character is reached, returning None
until the line over the limit
has been fully discarded. After that point, calls to decode
will
function as normal.
§Note
Setting a length limit is highly recommended for any LinesCodec
which
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 \n
characters, causing unbounded memory consumption.
Sourcepub fn max_length(&self) -> usize
pub fn max_length(&self) -> usize
Returns the maximum line length when decoding.
use std::usize;
use tokio_util::codec::LinesCodec;
let codec = LinesCodec::new();
assert_eq!(codec.max_length(), usize::MAX);
use tokio_util::codec::LinesCodec;
let codec = LinesCodec::new_with_max_length(256);
assert_eq!(codec.max_length(), 256);
Trait Implementations§
Source§impl Clone for LinesCodec
impl Clone for LinesCodec
Source§fn clone(&self) -> LinesCodec
fn clone(&self) -> LinesCodec
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl Debug for LinesCodec
impl Debug for LinesCodec
Source§impl Decoder for LinesCodec
impl Decoder for LinesCodec
Source§type Error = LinesCodecError
type Error = LinesCodecError
Source§fn decode(
&mut self,
buf: &mut BytesMut,
) -> Result<Option<String>, LinesCodecError>
fn decode( &mut self, buf: &mut BytesMut, ) -> Result<Option<String>, LinesCodecError>
Source§fn decode_eof(
&mut self,
buf: &mut BytesMut,
) -> Result<Option<String>, LinesCodecError>
fn decode_eof( &mut self, buf: &mut BytesMut, ) -> Result<Option<String>, LinesCodecError>
Source§impl Default for LinesCodec
impl Default for LinesCodec
Source§impl<T> Encoder<T> for LinesCodec
impl<T> Encoder<T> for LinesCodec
Source§impl Hash for LinesCodec
impl Hash for LinesCodec
Source§impl Ord for LinesCodec
impl Ord for LinesCodec
Source§fn cmp(&self, other: &LinesCodec) -> Ordering
fn cmp(&self, other: &LinesCodec) -> Ordering
1.21.0 · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl PartialEq for LinesCodec
impl PartialEq for LinesCodec
Source§impl PartialOrd for LinesCodec
impl PartialOrd for LinesCodec
impl Eq for LinesCodec
impl StructuralPartialEq for LinesCodec
Auto Trait Implementations§
impl Freeze for LinesCodec
impl RefUnwindSafe for LinesCodec
impl Send for LinesCodec
impl Sync for LinesCodec
impl Unpin for LinesCodec
impl UnwindSafe for LinesCodec
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> WithSubscriber for T
impl<T> WithSubscriber for T
Source§fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
Source§fn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Layout§
Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...)
attributes. Please see the Rust Reference's “Type Layout” chapter for details on type layout guarantees.
Size: 24 bytes