Struct broot::content_search::ContentMatch
source · Expand description
a displayable representation of where the needle was found, with some text around
Fields§
§extract: String
§needle_start: usize
§needle_end: usize
Implementations§
source§impl ContentMatch
impl ContentMatch
sourcepub fn build(hay: &[u8], pos: usize, needle: &str, desired_len: usize) -> Self
pub fn build(hay: &[u8], pos: usize, needle: &str, desired_len: usize) -> Self
Examples found in repository?
src/content_search/needle.rs (line 222)
211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226
pub fn get_match<P: AsRef<Path>>(
&self,
hay_path: P,
desired_len: usize,
) -> Option<ContentMatch> {
let hay = match get_mmap(hay_path) {
Ok(hay) => hay,
_ => { return None; }
};
match self.search_mmap(&hay) {
ContentSearchResult::Found { pos } => {
Some(ContentMatch::build(&hay, pos, self.as_str(), desired_len))
}
_ => None,
}
}
More examples
src/pattern/content_regex_pattern.rs (lines 80-85)
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
pub fn try_get_content_match(
&self,
path: &Path,
desired_len: usize,
) -> io::Result<Option<ContentMatch>> {
for line in BufReader::new(File::open(path)?).lines() {
let line = line?;
if let Some(regex_match) = self.rex.find(line.as_str()) {
return Ok(Some(ContentMatch::build(
line.as_bytes(),
regex_match.start(),
regex_match.as_str(),
desired_len,
)));
}
}
Ok(None)
}
Trait Implementations§
source§impl Clone for ContentMatch
impl Clone for ContentMatch
source§fn clone(&self) -> ContentMatch
fn clone(&self) -> ContentMatch
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read more