#selector #search #path #self #source #engine

syn-select-next

一个轻量级的Rust源代码搜索选择器引擎

1个不稳定版本

0.3.0-alpha.12023年3月23日

#135数据库实现

Download history 24/week @ 2024-03-31 32/week @ 2024-04-07

4,106 每月下载量

MIT 协议

24KB
559

syn-select

Build Status Latest Version Documentation

一个轻量级的Rust代码搜索路径选择器。

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());
}

通配符

在通配符中使用 _ 作为路径段将匹配该位置上的任何元素。例如,在以下

mod imp {
    struct H;
}

mod imp2 {
    struct H;
}

选择器 _::H 将匹配名为 H 的结构体。


lib.rs:

一个库,用于通过路径在Rust代码中获取特定元素。

用法

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);

依赖

~295–730KB
~18K SLoC