{"action":"closed","issue":{"url":"https://api.github.com/repos/dtolnay/syn/issues/446","repository_url":"https://api.github.com/repos/dtolnay/syn","labels_url":"https://api.github.com/repos/dtolnay/syn/issues/446/labels{/name}","comments_url":"https://api.github.com/repos/dtolnay/syn/issues/446/comments","events_url":"https://api.github.com/repos/dtolnay/syn/issues/446/events","html_url":"https://github.com/dtolnay/syn/issues/446","id":336261140,"node_id":"MDU6SXNzdWUzMzYyNjExNDA=","number":446,"title":"Map from derive to fn impls","user":{"login":"daschl","id":29086,"node_id":"MDQ6VXNlcjI5MDg2","avatar_url":"https://avatars2.githubusercontent.com/u/29086?v=4","gravatar_id":"","url":"https://api.github.com/users/daschl","html_url":"https://github.com/daschl","followers_url":"https://api.github.com/users/daschl/followers","following_url":"https://api.github.com/users/daschl/following{/other_user}","gists_url":"https://api.github.com/users/daschl/gists{/gist_id}","starred_url":"https://api.github.com/users/daschl/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/daschl/subscriptions","organizations_url":"https://api.github.com/users/daschl/orgs","repos_url":"https://api.github.com/users/daschl/repos","events_url":"https://api.github.com/users/daschl/events{/privacy}","received_events_url":"https://api.github.com/users/daschl/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":4,"created_at":"2018-06-27T14:44:17Z","updated_at":"2018-06-27T18:05:22Z","closed_at":"2018-06-27T18:05:22Z","author_association":"NONE","body":"Hi,\r\n\r\nif this is not the right place to ask questions let me know.\r\n\r\nI have a use case where based on a custom derive I need to iterate its fn impls. I know there is no direct mapping easily available.\r\n\r\nImagine I have the following code:\r\n\r\n```rust\r\n#[derive(Debug, RoastExport)]\r\nstruct Foobar {}\r\n\r\nimpl Foobar {\r\n    pub fn hello() -> i32 {\r\n        5678\r\n    }\r\n}\r\n```\r\n\r\nWhat I want in the end is a vec of all the function syntax items in the impl since based on that I need to do do codegen for FFI bindings.\r\n\r\nI don't mind writing some weird code but I have no idea how to \"map\" my ident from the derive to iterating over the full syntax from the files:\r\n\r\n```rust\r\n#[proc_macro_derive(RoastExport)]\r\npub fn roast_export(input: TokenStream) -> TokenStream {\r\n    let input: DeriveInput = syn::parse(input).unwrap();\r\n\r\n    functions_for_ident(&input.ident);\r\n\r\n    let expanded = quote!{};\r\n\r\n    expanded.into()\r\n}\r\n\r\nfn functions_for_ident(ident: &Ident) {\r\n    let rootdir = env::var(\"CARGO_MANIFEST_DIR\").unwrap();\r\n\r\n// iterate all rust files in the dir, looking for the struct/impls\r\n    for entry in WalkDir::new(rootdir) {\r\n        let e = entry.expect(\"could not decode entry\");\r\n        if e.file_name().to_str().unwrap().ends_with(\"rs\") {\r\n            let mut file = File::open(&e.path()).expect(\"Unable to open file\");\r\n            let mut src = String::new();\r\n            file.read_to_string(&mut src).expect(\"Unable to read file\");\r\n            let syntax = parse_file(&src).expect(\"Unable to parse file\");\r\n            for item in syntax.items {\r\n                // ???\r\n            }\r\n        }\r\n    }\r\n}\r\n```\r\n\r\nI appreciate any input or pointers to other projects who need something similar!"}}
{"actor":{"display_login":"daschl"}}