ripgrep-api
Coder-friendly Rust API wrapper around ripgrep's core crates.
Install
Crates.io:
= "0.1"
Git dependency (current repo):
= { = "https://github.com/AlextheYounga/ripgrep-api.git" }
Quickstart
use SearchBuilder;
let matches: = new
.path
.glob
.smart_case
.context
.build?
.collect;
for mat in matches
# Ok::
Streaming callbacks
use ;
let root = ".";
new
.path
.for_each?;
# Ok::
In-memory search
use SearchBuilder;
let haystack = b"zero\nmatch\nthree\n";
let matches = new
.search_slice?;
assert_eq!;
# Ok::
PCRE2 (feature flag)
#
#
Enable the feature in Cargo:
= { = "0.1", = ["pcre2"] }
Performance knobs
use SearchBuilder;
use MmapChoice;
let matches = new
.path
.threads
.memory_map
.heap_limit
.build?
.;
# Ok::
Custom file types and overrides
use SearchBuilder;
let matches = new
.path
.type_add
.type_
.glob
.build?
.;
# Ok::
rg flag -> API method
| rg flag | API method |
|---|---|
-g/--glob |
glob(...) |
-t/--type |
type_(...) |
-T/--type-not |
type_not(...) |
-d/--max-depth |
max_depth(...) |
--max-filesize |
max_filesize(...) |
-i/--ignore-case |
ignore_case() |
-S/--smart-case |
smart_case() |
-w/--word-regexp |
word() |
-x/--line-regexp |
line_regexp() |
-A/--after-context |
after_context(...) |
-B/--before-context |
before_context(...) |
-C/--context |
context(...) |
-m/--max-count |
max_count(...) |
-uuu |
hidden() + ignore(false) |
-P/--pcre2 |
pcre2() (feature: pcre2) |
-j/--threads |
threads(...) |
--mmap |
memory_map(...) |
--no-mmap |
memory_map(MmapChoice::never()) |
--heap-limit |
heap_limit(...) |