1个不稳定版本
0.3.0-alpha.1 | 2023年3月23日 |
---|
#135 在 数据库实现
4,106 每月下载量
24KB
559 行
syn-select
一个轻量级的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