pub struct StreamingParserConfig {
pub max_line_length: usize,
pub max_indent_depth: usize,
pub buffer_size: usize,
pub timeout: Option<Duration>,
}Expand description
Configuration options for the streaming parser.
Controls memory limits, buffer sizes, and timeout behavior.
§Examples
§Default Configuration
use hedl_stream::StreamingParserConfig;
let config = StreamingParserConfig::default();
assert_eq!(config.max_line_length, 1_000_000);
assert_eq!(config.max_indent_depth, 100);
assert_eq!(config.buffer_size, 64 * 1024);
assert_eq!(config.timeout, None);§Custom Configuration for Large Files
use hedl_stream::StreamingParserConfig;
let config = StreamingParserConfig {
max_line_length: 10_000_000, // 10MB lines
max_indent_depth: 1000, // Deep nesting
buffer_size: 256 * 1024, // 256KB buffer
timeout: None, // No timeout
};§Configuration for Untrusted Input
use hedl_stream::StreamingParserConfig;
use std::time::Duration;
let config = StreamingParserConfig {
max_line_length: 100_000, // Limit line length
max_indent_depth: 50, // Limit nesting
buffer_size: 32 * 1024, // Smaller buffer
timeout: Some(Duration::from_secs(10)), // 10 second timeout
};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.
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