{"id":13648623,"url":"https://github.com/wangrunji0408/call-dispatch-macro","last_synced_at":"2025-04-12T15:32:11.311Z","repository":{"id":83782021,"uuid":"343750668","full_name":"wangrunji0408/call-dispatch-macro","owner":"wangrunji0408","description":"[WIP] Generate function call dispatcher in Rust procedural macro.","archived":false,"fork":false,"pushed_at":"2021-03-02T11:56:58.000Z","size":5,"stargazers_count":6,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-10T12:29:36.789Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/wangrunji0408.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2021-03-02T11:28:05.000Z","updated_at":"2021-03-05T13:01:55.000Z","dependencies_parsed_at":"2023-10-17T04:40:12.044Z","dependency_job_id":null,"html_url":"https://github.com/wangrunji0408/call-dispatch-macro","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wangrunji0408%2Fcall-dispatch-macro","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wangrunji0408%2Fcall-dispatch-macro/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wangrunji0408%2Fcall-dispatch-macro/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wangrunji0408%2Fcall-dispatch-macro/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/wangrunji0408","download_url":"https://codeload.github.com/wangrunji0408/call-dispatch-macro/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248589425,"owners_count":21129611,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-02T01:04:24.345Z","updated_at":"2025-04-12T15:32:11.276Z","avatar_url":"https://github.com/wangrunji0408.png","language":"Rust","funding_links":[],"categories":["Rust"],"sub_categories":[],"readme":"# call-dispatch-macro\n\n[![Actions Status](https://github.com/wangrunji0408/call-dispatch-macro/workflows/CI/badge.svg)](https://github.com/wangrunji0408/call-dispatch-macro/actions)\n\nGenerate function call dispatcher in Rust procedural macro.\n\n🚧 Working In Progress 🚧\n\n## Usage\n\n```rust\nuse call_dispatch_macro::call_dispatch;\n\n// Define a struct.\nstruct Syscall;\n\n// Put `call_dispatch` attribute on the impl block.\n#[call_dispatch]\nimpl Syscall {\n    // Mark the dispatcher function.\n    #[dispatcher(match_arm_prefix = \"sys\")]\n    fn dispatch(\u0026mut self, num: u32, args: [usize; 6]) -\u003e Option\u003ci32\u003e {\n        // The body will be rewritten by the macro.\n        panic!(\"code generated by macro\")\n        // ======== Generated Code Start ========\n        match num {\n            sys::SYS_READ =\u003e Some(self.sys_read(args[0] as _, args[1] as _, args[2] as _)),\n            sys::SYS_WRITE =\u003e Some(self.sys_write(args[0] as _, args[1] as _, args[2] as _)),\n            _ =\u003e None,\n        }\n        // ========= Generated Code End =========\n    }\n\n    // Mark the function to be dispatched.\n    #[call]\n    fn sys_read(\u0026mut self, fd: i32, buf: *mut u8, len: usize) -\u003e i32 {\n        println!(\"sys_read: fd={:?}, buf=({:?}; {:?})\", fd, buf, len);\n        1\n    }\n    #[call]\n    fn sys_write(\u0026mut self, fd: i32, buf: *const u8, len: usize) -\u003e i32 {\n        println!(\"sys_write: fd={:?}, buf=({:?}; {:?})\", fd, buf, len);\n        2\n    }\n}\n\n// Define constants for match number.\nmod sys {\n    pub const SYS_READ: u32 = 1;\n    pub const SYS_WRITE: u32 = 2;\n}\n\nfn main() {\n    let mut syscall = Syscall;\n    assert_eq!(syscall.dispatch(0, [1, 2, 3, 4, 5, 6]), None);\n    assert_eq!(syscall.dispatch(1, [1, 2, 3, 4, 5, 6]), Some(1));\n    assert_eq!(syscall.dispatch(2, [1, 2, 3, 4, 5, 6]), Some(2));\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwangrunji0408%2Fcall-dispatch-macro","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwangrunji0408%2Fcall-dispatch-macro","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwangrunji0408%2Fcall-dispatch-macro/lists"}