Skip to content

Commit 560c473

Browse files
committed
enhance: parser builder with mmap support
1 parent 2065eae commit 560c473

4 files changed

Lines changed: 697 additions & 27 deletions

File tree

.github/workflows/rust-check.yml

Lines changed: 0 additions & 23 deletions
This file was deleted.

src/builder.rs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,11 @@ pub enum AnyParser<'a> {
202202
}
203203

204204
impl ParserBuilder {
205-
pub fn build_any<'a>(&self, data: Option<&'a [u8]>) -> crate::Result<AnyParser<'a>> {
205+
pub fn build_any<'a>(
206+
&self,
207+
data: Option<&'a [u8]>,
208+
mmap_path: Option<&std::path::Path>,
209+
) -> crate::Result<AnyParser<'a>> {
206210
match self.config.mode {
207211
ParserMode::Simple => Ok(AnyParser::Simple(Box::new(self.build_simple()))),
208212
ParserMode::Batch => Ok(AnyParser::Batch(Box::new(self.build_batch()))),
@@ -220,9 +224,14 @@ impl ParserBuilder {
220224
})?;
221225
Ok(AnyParser::ZeroCopy(self.build_zerocopy(d)))
222226
}
223-
ParserMode::Mmap => Err(crate::ParseError::InvalidArgument(
224-
"Mmap mode requires a file path, use build_mmap instead".to_string(),
225-
)),
227+
ParserMode::Mmap => {
228+
let path = mmap_path.ok_or_else(|| {
229+
crate::ParseError::InvalidArgument(
230+
"Mmap mode requires a file path to be provided".to_string(),
231+
)
232+
})?;
233+
Ok(AnyParser::Mmap(Box::new(self.build_mmap(path)?)))
234+
}
226235
}
227236
}
228237
}

0 commit comments

Comments
 (0)