Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add indices to MatchRange (v1.12 feature) #632

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion src/search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,17 @@ use std::collections::HashMap;
pub struct MatchRange {
pub start: usize,
pub length: usize,

/// If the match is somewhere inside a (potentially nested) array, this
/// field is set to the index/indices of the matched element(s).
///
/// In the simple case, if the field has the value `["foo", "bar"]`, then
/// searching for `ba` will return `indices: Some([1])`. If the value
/// contains multiple nested arrays, the first index describes the most
/// top-level array, and descending from there. For example, if the value is
/// `[{ x: "cat" }, "bear", { y: ["dog", "fox"] }]`, searching for `dog`
/// will return `indices: Some([2, 0])`.
pub indices: Option<Vec<usize>>,
}

#[derive(Serialize, Debug, Eq, PartialEq, Clone)]
Expand Down Expand Up @@ -1122,7 +1133,8 @@ mod tests {
.unwrap(),
&vec![MatchRange {
start: 0,
length: 5
length: 5,
indices: None,
}]
);
Ok(())
Expand Down
Loading