#selector #source #search #path #wildcard #element #self

syn-select

A lightweight selector engine for searching Rust source code

8 releases

0.3.0 May 22, 2023
0.2.1 Jun 16, 2022
0.2.0 Aug 23, 2019
0.1.4 Feb 11, 2019
0.1.2 Jan 30, 2019

#109 in Database implementations

Download history 7598/week @ 2023-12-23 11387/week @ 2023-12-30 10450/week @ 2024-01-06 10269/week @ 2024-01-13 7123/week @ 2024-01-20 6897/week @ 2024-01-27 9171/week @ 2024-02-03 7879/week @ 2024-02-10 8087/week @ 2024-02-17 7639/week @ 2024-02-24 8458/week @ 2024-03-02 4210/week @ 2024-03-09 4208/week @ 2024-03-16 5425/week @ 2024-03-23 7394/week @ 2024-03-30 8751/week @ 2024-04-06

26,300 downloads per month
Used in 7 crates (3 directly)

MIT license

24KB
559 lines

syn-select

Build Status Latest Version Documentation

Lightweight path selector for searching Rust code.

mod a {
    mod b {
        trait C {
            fn d(self) {}

            fn f() {}
        }
    }
}

fn main() {
    let src_file = syn::parse_str(include_str!("./rs")).unwrap();

    // This will print out the trait `C`, limited to only function `d`.
    dbg!(syn_select::select("a::b::C::d", &src_file).unwrap());
}

Wildcards

Using _ as a path segment in a wildcard will match any element in that position. For example, in the following:

mod imp {
    struct H;
}

mod imp2 {
    struct H;
}

The selector _::H would match both structs named H.


lib.rs:

Library to get a specific element by path in Rust code.

Usage

let file: syn::File = syn::parse_str(
    r#"
    mod a {
        mod b {
            trait C {
                fn d(self) {}
                fn f() {}
            }
        }
    }"#).unwrap();
let results = syn_select::select("a::b::C::d", &file).unwrap();
assert_eq!(results.len(), 1);

Dependencies

~310–740KB
~18K SLoC