pub struct MmapInput { /* private fields */ }
Expand description
Input wrapping a memory mapped file.
Implementations§
Source§impl MmapInput
impl MmapInput
Sourcepub unsafe fn map_file<D: MmapAsRawDesc>(
file_desc: D,
) -> Result<Self, InputError>
pub unsafe fn map_file<D: MmapAsRawDesc>( file_desc: D, ) -> Result<Self, InputError>
Map a file to memory.
§Safety
This operation is inherently unsafe, since the file can be modified in or out of process. See Mmap documentation.
§Errors
Calling mmap might result in an IO error.
Examples found in repository?
examples/approx_spans_usage.rs (line 22)
8fn main() -> Result<ExitCode, Box<dyn Error>> {
9 let args: Vec<_> = env::args().collect();
10
11 if args.len() != 3 {
12 eprintln!("provide exactly two arguments, query and file path");
13 return Ok(ExitCode::FAILURE);
14 }
15
16 let query_arg = &args[1];
17 let file_path = &args[2];
18
19 let query = rsonpath_syntax::parse(query_arg)?;
20 let file = fs::File::open(file_path)?;
21 // SAFETY: File is kept open until end of the run.
22 let input = unsafe { MmapInput::map_file(&file)? };
23 let stdout_lock = io::stdout().lock();
24 let mut sink = MatchWriter::from(stdout_lock);
25
26 let engine = RsonpathEngine::compile_query(&query)?;
27
28 engine.approximate_spans(&input, &mut sink)?;
29
30 Ok(ExitCode::SUCCESS)
31}
Trait Implementations§
Source§impl Input for MmapInput
impl Input for MmapInput
Source§type BlockIterator<'a, 'r, R, const N: usize> = BorrowedBytesBlockIterator<'r, EndPaddedInput<'a>, R, N>
where
R: InputRecorder<&'a [u8]> + 'r
type BlockIterator<'a, 'r, R, const N: usize> = BorrowedBytesBlockIterator<'r, EndPaddedInput<'a>, R, N> where R: InputRecorder<&'a [u8]> + 'r
Type of the iterator used by
iter_blocks
, parameterized
by the lifetime of source input and the size of the block.Source§type Error = Infallible
type Error = Infallible
Type of errors that can occur when operating on this
Input
.Source§fn leading_padding_len(&self) -> usize
fn leading_padding_len(&self) -> usize
Return the length of the padding added at the start of the input. Read more
Source§fn trailing_padding_len(&self) -> usize
fn trailing_padding_len(&self) -> usize
Return the length of the padding added at the end of the input. Read more
Source§fn len_hint(&self) -> Option<usize>
fn len_hint(&self) -> Option<usize>
Return the length of the entire input, if known. Read more
Source§fn iter_blocks<'a, 'r, R, const N: usize>(
&'a self,
recorder: &'r R,
) -> Self::BlockIterator<'a, 'r, R, N>where
R: InputRecorder<&'a [u8]>,
fn iter_blocks<'a, 'r, R, const N: usize>(
&'a self,
recorder: &'r R,
) -> Self::BlockIterator<'a, 'r, R, N>where
R: InputRecorder<&'a [u8]>,
Iterate over blocks of size
N
of the input.
N
has to be a power of two larger than 1.Source§fn seek_backward(&self, from: usize, needle: u8) -> Option<usize>
fn seek_backward(&self, from: usize, needle: u8) -> Option<usize>
Search for an occurrence of
needle
in the input,
starting from from
and looking back. Returns the index
of the first occurrence or None
if the needle
was not found.Source§fn seek_forward<const N: usize>(
&self,
from: usize,
needles: [u8; N],
) -> Result<Option<(usize, u8)>, Infallible>
fn seek_forward<const N: usize>( &self, from: usize, needles: [u8; N], ) -> Result<Option<(usize, u8)>, Infallible>
Search for an occurrence of any of the
needles
in the input,
starting from from
and looking forward. Returns the index
of the first occurrence and the needle found, or None
if none of the needles
were not found. Read moreSource§fn seek_non_whitespace_forward(
&self,
from: usize,
) -> Result<Option<(usize, u8)>, Infallible>
fn seek_non_whitespace_forward( &self, from: usize, ) -> Result<Option<(usize, u8)>, Infallible>
Search for the first byte in the input that is not ASCII whitespace
starting from
from
. Returns a pair: the index of first such byte,
and the byte itself; or None
if no non-whitespace characters
were found. Read moreSource§fn seek_non_whitespace_backward(&self, from: usize) -> Option<(usize, u8)>
fn seek_non_whitespace_backward(&self, from: usize) -> Option<(usize, u8)>
Search for the first byte in the input that is not ASCII whitespace
starting from
from
and looking back. Returns a pair:
the index of first such byte, and the byte itself;
or None
if no non-whitespace characters were found.Source§fn is_member_match(
&self,
from: usize,
to: usize,
member: &StringPattern,
) -> Result<bool, Self::Error>
fn is_member_match( &self, from: usize, to: usize, member: &StringPattern, ) -> Result<bool, Self::Error>
Decide whether the slice of input between
from
(inclusive)
and to
(exclusive) matches the member
(comparing bitwise,
including double quotes delimiters). Read moreAuto Trait Implementations§
impl Freeze for MmapInput
impl RefUnwindSafe for MmapInput
impl Send for MmapInput
impl Sync for MmapInput
impl Unpin for MmapInput
impl UnwindSafe for MmapInput
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more