syn-select
syn-select copied to clipboard
Add selection for associated functions
Based upon cargo expand issue 168
struct MyType {
foo: usize,
}
impl MyType {
fn print_foo(&self) {
println!("{}", self.foo);
}
}
It would be nice to be able to filter for MyType::print_foo, but currently it seems this is not possible.
What does syn say the type of the print_foo declaration is?
The impl block has the type Item::Impl and the associated function is ImplItem::Fn.
The complete (debug) output is:
File { shebang: None, attrs: [], items: [Item::Struct { attrs: [], vis: Visibility::Inherited, struct_token: Struct, ident: Ident(MyType), generics: Generics { lt_token: None, params: [], gt_token: None, where_clause: None }, fields: Fields::Named { brace_token: Brace, named: [Field { attrs: [], vis: Visibility::Inherited, mutability: FieldMutability::None, ident: Some(Ident(foo)), colon_token: Some(Colon), ty: Type::Path { qself: None, path: Path { leading_colon: None, segments: [PathSegment { ident: Ident(usize), arguments: PathArguments::None }] } } }, Comma] }, semi_token: None }, Item::Impl { attrs: [], defaultness: None, unsafety: None, impl_token: Impl, generics: Generics { lt_token: None, params: [], gt_token: None, where_clause: None }, trait_: None, self_ty: Type::Path { qself: None, path: Path { leading_colon: None, segments: [PathSegment { ident: Ident(MyType), arguments: PathArguments::None }] } }, brace_token: Brace, items: [ImplItem::Fn { attrs: [], vis: Visibility::Inherited, defaultness: None, sig: Signature { constness: None, asyncness: None, unsafety: None, abi: None, fn_token: Fn, ident: Ident(print_foo), generics: Generics { lt_token: None, params: [], gt_token: None, where_clause: None }, paren_token: Paren, inputs: [FnArg::Receiver(Receiver { attrs: [], reference: Some((And, None)), mutability: None, self_token: SelfValue, colon_token: None, ty: Type::Reference { and_token: And, lifetime: None, mutability: None, elem: Type::Path { qself: None, path: Path { leading_colon: None, segments: [PathSegment { ident: Ident(Self), arguments: PathArguments::None }] } } } })], variadic: None, output: ReturnType::Default }, block: Block { brace_token: Brace, stmts: [Stmt::Macro { attrs: [], mac: Macro { path: Path { leading_colon: None, segments: [PathSegment { ident: Ident(println), arguments: PathArguments::None }] }, bang_token: Not, delimiter: MacroDelimiter::Paren(Paren), tokens: TokenStream [Literal { lit: "{}" }, Punct { char: ',', spacing: Alone }, Ident { sym: self }, Punct { char: '.', spacing: Alone }, Ident { sym: foo }] }, semi_token: Some(Semi) }] } }] }] }