Skip to main content

LineParsingOptions

Struct LineParsingOptions 

Source
pub struct LineParsingOptions {
    pub max_line_length: NumBytes,
    pub overflow_behavior: LineOverflowBehavior,
    pub buffer_compaction_threshold: Option<NumBytes>,
}
Expand description

Configuration options for parsing lines from a stream.

Fields§

§max_line_length: NumBytes

Maximum length of a single line in bytes. When reached, further data won’t be appended to the current line. The line will be emitted in its current state.

Must be greater than zero for any line-consuming visitor (inspect_lines, collect_lines, wait_for_line, collect_lines_into_write, collect_lines_into_vec). Constructing such a consumer with max_line_length = 0 panics. If you want effectively unbounded line parsing — i.e. accept arbitrarily long lines from a trusted source — pass NumBytes::MAX explicitly instead of zero. Remember that a malicious or misbehaving stream that writes endless data without a line break would otherwise hold memory until the process runs out: the explicit MAX makes that decision visible at the call site.

Defaults to DEFAULT_MAX_LINE_LENGTH.

§overflow_behavior: LineOverflowBehavior

What should happen when a line is too long?

When lossy buffering drops chunks before they reach the parser, line-based consumers conservatively discard any partial line and resynchronizes at the next newline instead of joining bytes across the gap.

Defaults to LineOverflowBehavior::DropAdditionalData.

§buffer_compaction_threshold: Option<NumBytes>

Optional cap on each parser’s long-term-retained buffer capacity.

The parser keeps two BytesMut buffers (the in-progress line and the most-recently emitted line): each retains capacity for the parser’s lifetime, growing to fit the largest line they have ever held. For most workloads this is fine. The worst case is roughly 2 × max_line_length memory used per parser.

Set this to Some(n) when a stream has mostly small lines but occasional large outliers (especially under NumBytes::MAX / “trusted unbounded” line parsing) and you want the buffers to release their allocations after each outlier instead of staying at outlier-size forever. At the start of each LineParser::next_line call, any buffer whose capacity exceeds n is dropped and replaced with an empty buffer. The next line re-grows it from zero.

None (the default) preserves the “no compaction” behavior. Buffers stay at their largest observed size. A sensible enabled value could be 1.5 × typical_line_size. Setting it to close to (or below) typical line sizes will trigger reallocation almost every line and slow the parser unnecessarily. When your max_line_length is already small, you may ignore this setting if max consumption is not an issue on your system.

Compaction reduces the parser’s steady-state memory after outliers; it does not change the peak. Peak memory is bounded by max_line_length regardless of this setting. Compaction is also best-effort: a partially-buffered line that has not yet finished may briefly retain over-threshold capacity until the line completes.

Defaults to None.

Implementations§

Source§

impl LineParsingOptions

Source

pub fn builder() -> LineParsingOptionsBuilder<((), (), ())>

Create a builder for building LineParsingOptions. On the builder, call .max_line_length(...), .overflow_behavior(...), .buffer_compaction_threshold(...) to set the values of the fields. Finally, call .build() to create the instance of LineParsingOptions.

Trait Implementations§

Source§

impl Clone for LineParsingOptions

Source§

fn clone(&self) -> LineParsingOptions

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for LineParsingOptions

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for LineParsingOptions

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl PartialEq for LineParsingOptions

Source§

fn eq(&self, other: &LineParsingOptions) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Copy for LineParsingOptions

Source§

impl Eq for LineParsingOptions

Source§

impl StructuralPartialEq for LineParsingOptions

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> Sink for T
where T: Send + 'static,