Skip to main content

ripgrep_api/
types.rs

1use std::path::PathBuf;
2
3/// A structured match result.
4///
5/// ```rust
6/// use ripgrep_api::SearchBuilder;
7///
8/// let mut matches = SearchBuilder::new("alpha")
9///     .path(".")
10///     .max_count(1)
11///     .build()?
12///     .collect::<Vec<_>>();
13///
14/// let first = matches.pop().unwrap();
15/// println!("{}:{}", first.path.display(), first.line.unwrap_or(0));
16/// # Ok::<(), ripgrep_api::SearchError>(())
17/// ```
18#[derive(Debug, Clone)]
19pub struct Match {
20    pub path: PathBuf,
21    pub line: Option<u64>,
22    pub column: Option<usize>,
23    pub bytes: Vec<u8>,
24    pub submatches: Vec<SubMatch>,
25    pub line_text: String,
26    pub context: Vec<ContextLine>,
27}
28
29#[derive(Debug, Clone)]
30pub struct SubMatch {
31    pub start: usize,
32    pub end: usize,
33}
34
35#[derive(Debug, Clone)]
36pub struct ContextLine {
37    pub path: PathBuf,
38    pub kind: ContextKind,
39    pub line: Option<u64>,
40    pub bytes: Vec<u8>,
41    pub line_text: String,
42}
43
44#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
45pub enum ContextKind {
46    Before,
47    After,
48    Other,
49}