{"id":33919645,"url":"https://github.com/openbytedev/fn-ptr","last_synced_at":"2026-01-13T14:00:55.627Z","repository":{"id":326433998,"uuid":"1104123326","full_name":"OpenByteDev/fn-ptr","owner":"OpenByteDev","description":"A utility crate for introspecting and rewriting function pointer types at compile time","archived":false,"fork":false,"pushed_at":"2026-01-12T02:18:21.000Z","size":158,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2026-01-12T05:57:31.554Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/OpenByteDev.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-11-25T19:35:15.000Z","updated_at":"2026-01-12T02:18:25.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/OpenByteDev/fn-ptr","commit_stats":null,"previous_names":["openbytedev/fn-ptr"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/OpenByteDev/fn-ptr","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OpenByteDev%2Ffn-ptr","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OpenByteDev%2Ffn-ptr/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OpenByteDev%2Ffn-ptr/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OpenByteDev%2Ffn-ptr/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/OpenByteDev","download_url":"https://codeload.github.com/OpenByteDev/fn-ptr/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OpenByteDev%2Ffn-ptr/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28387596,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-13T13:42:20.960Z","status":"ssl_error","status_checked_at":"2026-01-13T13:42:03.276Z","response_time":56,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":"2025-12-12T08:58:36.521Z","updated_at":"2026-01-13T14:00:55.615Z","avatar_url":"https://github.com/OpenByteDev.png","language":"Rust","readme":"# fn-ptr\n\n[![CI](https://github.com/OpenByteDev/fn-ptr/actions/workflows/ci.yml/badge.svg)](https://github.com/OpenByteDev/fn-ptr/actions/workflows/ci.yml) [![crates.io](https://img.shields.io/crates/v/fn-ptr.svg)](https://crates.io/crates/fn-ptr) [![Documentation](https://docs.rs/fn-ptr/badge.svg)](https://docs.rs/fn-ptr) [![dependency status](https://deps.rs/repo/github/openbytedev/fn-ptr/status.svg)](https://deps.rs/repo/github/openbytedev/fn-ptr) [![MIT](https://img.shields.io/crates/l/fn-ptr.svg)](https://github.com/OpenByteDev/fn-ptr/blob/master/LICENSE)\n\nThis is a utility crate for **introspecting** and **rewriting** function pointer types at compile time.\n\nIt implements [`FnPtr`](https://docs.rs/fn-ptr/latest/fn_ptr/trait.FnPtr.html) for all function-pointer types:\n- `fn(T) -\u003e U`\n- `unsafe fn(T) -\u003e U`\n- `extern \"C-unwind\" fn(T)`\n- `unsafe extern \"sysv64\" fn() -\u003e i32`\n\n## Function pointer metadata\n\n[`FnPtr`](https://docs.rs/fn-ptr/latest/fn_ptr/trait.FnPtr.html) exposes metadata as associated types/consts.\n\n```rust\nuse fn_ptr::{FnPtr, AbiValue};\n\ntype F = extern \"C\" fn(i32, i32) -\u003e i32;\nassert_eq!(\u003cF as FnPtr\u003e::ARITY, 2);\nassert_eq!(\u003cF as FnPtr\u003e::IS_SAFE, true);\nassert_eq!(\u003cF as FnPtr\u003e::IS_EXTERN, true);\nassert_eq!(\u003cF as FnPtr\u003e::ABI, AbiValue::C { unwind: false });\n```\n\nErgonomic const functions are provided as well:\n\n```rust\nconst A: usize = fn_ptr::arity::\u003cF\u003e();\nconst SAFE: bool = fn_ptr::is_safe::\u003cF\u003e();\nconst EXT: bool = fn_ptr::is_extern::\u003cF\u003e();\nconst ABI: AbiValue = fn_ptr::abi::\u003cF\u003e();\n```\n\n## Rewriting function-pointer types\n\nThe crate provides type-level rewriting via traits:\n\n- **abi:** [`WithAbi`](https://docs.rs/fn-ptr/latest/fn_ptr/trait.WithAbi.html) / [`with_abi!`](https://docs.rs/fn-ptr/latest/fn_ptr/macro.with_abi.html)\n- **Safety:** [`WithSafety`](https://docs.rs/fn-ptr/latest/fn_ptr/trait.WithSafety.html) / [`with_safety!`](https://docs.rs/fn-ptr/latest/fn_ptr/macro.with_safety.html) ([`make_safe!`](https://docs.rs/fn-ptr/latest/fn_ptr/macro.make_unsafe.html), [`make_unsafe!`](https://docs.rs/fn-ptr/latest/fn_ptr/macro.make_unsafe.html))\n- **Output:** [`WithOutput`](https://docs.rs/fn-ptr/latest/fn_ptr/trait.WithOutput.html) / [`with_output!`](https://docs.rs/fn-ptr/latest/fn_ptr/macro.with_output.html)\n- **Args:** [`WithArgs`](https://docs.rs/fn-ptr/latest/fn_ptr/trait.WithArgs.html) / [`with_args!`](https://docs.rs/fn-ptr/latest/fn_ptr/macro.with_args.html)\n\n### Type-level transformations\n\nThe macros compute a new function-pointer **type** while preserving everything else.\n\n```rust\nuse fn_ptr::{with_abi, with_safety, with_output, with_args};\n\ntype F = extern \"C\" fn(i32) -\u003e i32;\n\ntype F1 = with_abi!(\"sysv64\", F);   // extern \"sysv64\" fn(i32) -\u003e i32\ntype F2 = with_safety!(unsafe, F);  // unsafe extern \"C\" fn(i32) -\u003e i32\ntype F3 = with_output!(u64, F);     // extern \"C\" fn(i32) -\u003e u64\ntype F4 = with_args!((u8, u16), F); // extern \"C\" fn(u8, u16) -\u003e i32\n```\n\n### Value-level casts\n\nThe same transformations exist at the value level via methods on [`FnPtr`](https://docs.rs/fn-ptr/latest/fn_ptr/trait.FnPtr.html).\nThese casts are only [`transmuting`](https://doc.rust-lang.org/std/mem/fn.transmute.html) and do **not** the actual underlying function.\n\n```rust\nuse fn_ptr::{FnPtr, abi};\n\nlet f: fn(i32, i32) -\u003e i32 = |a, b| a + b;\n\n// safety\nlet u: unsafe fn(i32, i32) -\u003e i32 = f.as_unsafe();\nlet f2: fn(i32, i32) -\u003e i32 = unsafe { u.as_safe() };\n\n// abi\nlet c: extern \"C\" fn(i32, i32) -\u003e i32 = unsafe { f.with_abi::\u003cabi!(\"C\")\u003e() };\n\n// output\nlet out: fn(i32, i32) -\u003e u64 = unsafe { f.with_output::\u003cu64\u003e() };\n\n// args\nlet args: fn(u8, u16) -\u003e i32 = unsafe { f.with_args::\u003c(u8, u16)\u003e() };\n\n# assert_eq!(f.addr(), f2.addr());\n# assert_eq!(f.addr(), c.addr());\n# assert_eq!(f.addr(), out.addr());\n# assert_eq!(f.addr(), args.addr());\n```\n## How it works\n\nImplementations are generated by a large [macro]((https://github.com/OpenByteDev/fn-ptr/blob/master/src/impl.rs)). The rewrite macros are thin wrappers\nover the traits [`WithAbi`](https://docs.rs/fn-ptr/latest/fn_ptr/trait.WithAbi.html), [`WithSafety`](https://docs.rs/fn-ptr/latest/fn_ptr/trait.WithSafety.html), [`WithOutput`](https://docs.rs/fn-ptr/latest/fn_ptr/trait.WithOutput.html), [`WithArgs`](https://docs.rs/fn-ptr/latest/fn_ptr/trait.WithArgs.html) (and the corresponding `*Impl` helper traits).\n\n## License\n\nLicensed under the MIT license, see [LICENSE](https://github.com/OpenByteDev/fn-ptr/blob/master/LICENSE) for details.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fopenbytedev%2Ffn-ptr","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fopenbytedev%2Ffn-ptr","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fopenbytedev%2Ffn-ptr/lists"}