pub struct StreamingParserConfig {
pub max_line_length: usize,
pub max_indent_depth: usize,
pub buffer_size: usize,
pub timeout: Option<Duration>,
pub memory_limits: MemoryLimits,
pub enable_pooling: bool,
}Expand description
Configuration options for the streaming parser.
Controls memory limits, buffer sizes, timeout behavior, and buffer pooling.
Fields§
§max_line_length: usizeMaximum line length in bytes.
Lines exceeding this length will cause a parsing error. This protects against malformed input with extremely long lines that could exhaust memory.
Default: 1,000,000 bytes (1MB)
max_indent_depth: usizeMaximum indentation depth.
Indentation levels exceeding this depth will cause a parsing error. This protects against deeply nested structures that could cause stack overflow or performance issues.
Default: 100 levels
buffer_size: usizeBuffer size for reading input.
Larger buffers can improve performance for large files by reducing the number of system calls, but use more memory.
Default: 64KB
timeout: Option<Duration>Timeout for parsing operations.
If set, the parser will return a StreamError::Timeout if parsing takes
longer than the specified duration. This protects against infinite loops
from malicious or malformed input.
Set to None to disable timeout checking (default for trusted input).
Default: None (no timeout)
§Performance Note
Timeout checking is performed periodically (every 100 operations) to minimize overhead. For very fast parsing, the actual timeout may slightly exceed the configured limit.
memory_limits: MemoryLimitsMemory limits for buffer management.
Controls maximum buffer sizes, line lengths, and pool configuration.
See MemoryLimits for preset configurations.
Default: MemoryLimits::default()
enable_pooling: boolEnable buffer pooling for high-throughput scenarios.
When enabled, the parser reuses string and value buffers across operations, reducing allocation overhead. Beneficial for processing many files in sequence or high-throughput server workloads.
Default: false (for backward compatibility)
Implementations§
Source§impl StreamingParserConfig
impl StreamingParserConfig
Sourcepub fn unlimited() -> Self
pub fn unlimited() -> Self
Config with no limits (use for trusted input only).
§Security Warning
This configuration removes the line length limit, which can expose your application to denial-of-service attacks if processing untrusted input. Only use this for trusted, controlled environments.
§Examples
use hedl_stream::StreamingParserConfig;
// For trusted input where you want to allow arbitrarily long lines
let config = StreamingParserConfig::unlimited();Sourcepub fn with_buffer_hint(self, hint: BufferSizeHint) -> Self
pub fn with_buffer_hint(self, hint: BufferSizeHint) -> Self
Configure buffer size using a size hint.
§Examples
use hedl_stream::{StreamingParserConfig, BufferSizeHint};
let config = StreamingParserConfig::default()
.with_buffer_hint(BufferSizeHint::Large);
assert_eq!(config.buffer_size, 256 * 1024);Sourcepub fn with_buffer_pooling(self, enabled: bool) -> Self
pub fn with_buffer_pooling(self, enabled: bool) -> Self
Enable or disable buffer pooling.
§Examples
use hedl_stream::StreamingParserConfig;
let config = StreamingParserConfig::default()
.with_buffer_pooling(true);
assert_eq!(config.enable_pooling, true);Sourcepub fn with_memory_limits(self, limits: MemoryLimits) -> Self
pub fn with_memory_limits(self, limits: MemoryLimits) -> Self
Configure memory limits.
§Examples
use hedl_stream::{StreamingParserConfig, MemoryLimits};
let config = StreamingParserConfig::default()
.with_memory_limits(MemoryLimits::high_throughput());Sourcepub fn with_pool_size(self, size: usize) -> Self
pub fn with_pool_size(self, size: usize) -> Self
Configure buffer pool size (when pooling is enabled).
§Examples
use hedl_stream::StreamingParserConfig;
let config = StreamingParserConfig::default()
.with_buffer_pooling(true)
.with_pool_size(50);
assert_eq!(config.memory_limits.max_pool_size, 50);Trait Implementations§
Source§impl Clone for StreamingParserConfig
impl Clone for StreamingParserConfig
Source§fn clone(&self) -> StreamingParserConfig
fn clone(&self) -> StreamingParserConfig
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more