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
Download history 9965/week @ 2024-06-12 8188/week @ 2024-06-19 7110/week @ 2024-06-26 9251/week @ 2024-07-03 9680/week @ 2024-07-10 9592/week @ 2024-07-17 9796/week @ 2024-07-24 10897/week @ 2024-07-31 10699/week @ 2024-08-07 10390/week @ 2024-08-14 9680/week @ 2024-08-21 8678/week @ 2024-08-28 8867/week @ 2024-09-04 10036/week @ 2024-09-11 9401/week @ 2024-09-18 8197/week @ 2024-09-25

37,726 downloads per month
Used in 8 crates (4 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

~260–690KB
~17K SLoC