Skip to main content

ReaderConfig

Struct ReaderConfig 

Source
pub struct ReaderConfig {
    pub max_segment_bytes: usize,
    pub max_segments: Option<usize>,
    pub max_input_bytes: Option<u64>,
    pub max_messages: Option<usize>,
}
Expand description

Configuration for reader-based EDIFACT parsers.

Pass to from_reader_with_config or from_bufread_stream_with_config to override default limits.

§Example

use edifact_rs::{ReaderConfig, from_reader_with_config};

let cfg = ReaderConfig::default().max_segment_bytes(4_096);
let segments: Vec<_> = from_reader_with_config(b"BGM+220+1+9'".as_ref(), cfg)
    .collect::<Result<_, _>>()
    .unwrap();
assert_eq!(segments[0].tag, "BGM");

Fields§

§max_segment_bytes: usize

Maximum allowed segment byte length (excluding the segment terminator).

If a segment accumulates more bytes than this limit without a terminator the parser returns EdifactError::SegmentTooLong. This prevents unbounded allocation when processing malformed or adversarially crafted input streams.

Default: 65 536 bytes (64 KiB). Real-world EDIFACT segments are almost always below 4 KiB; consider using a tighter limit for untrusted inputs.

§max_segments: Option<usize>

Maximum number of segments to yield before the stream stops.

Once this many segments have been produced the segment stream returns None, effectively truncating the message. Useful for preventing resource exhaustion when the total segment count in a message is expected to be bounded.

Default: None (unlimited).

§max_input_bytes: Option<u64>

Maximum total input bytes to consume before the stream stops.

The budget is checked before each segment is read. If bytes_consumed >= max_input_bytes at that point the stream stops immediately without reading any further data. A segment whose bytes push bytes_consumed above the threshold is still yielded (parsing cannot be abandoned mid-segment), but no subsequent segment will be started. Use in combination with max_segment_bytes for defence-in-depth against maliciously large inputs.

Default: None (unlimited).

§max_messages: Option<usize>

Maximum number of EDIFACT messages (UNH/UNT pairs) to process before the stream stops.

Once this many complete messages have been yielded the stream returns None. Useful for rate-limiting or sampling large interchanges without parsing the entire file.

Default: None (unlimited).

Implementations§

Source§

impl ReaderConfig

Source

pub fn max_segment_bytes(self, limit: usize) -> ReaderConfig

Set the maximum segment byte length and return self.

Source

pub fn max_segments(self, limit: usize) -> ReaderConfig

Set the maximum number of segments to yield and return self.

Source

pub fn max_input_bytes(self, limit: u64) -> ReaderConfig

Set the maximum total input bytes to consume and return self.

Source

pub fn max_messages(self, limit: usize) -> ReaderConfig

Set the maximum number of EDIFACT messages (UNH/UNT pairs) to yield and return self.

Trait Implementations§

Source§

impl Clone for ReaderConfig

Source§

fn clone(&self) -> ReaderConfig

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Copy for ReaderConfig

Source§

impl Debug for ReaderConfig

Source§

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

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

impl Default for ReaderConfig

Source§

fn default() -> ReaderConfig

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

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> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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.