https://github.com/williamvenner/fn_type_alias
✨ A proc attribute macro that generates a type alias with the given identifier for the attributed function
https://github.com/williamvenner/fn_type_alias
alias macro proc-macro proc-macro-attributes rust type
Last synced: about 1 year ago
JSON representation
✨ A proc attribute macro that generates a type alias with the given identifier for the attributed function
- Host: GitHub
- URL: https://github.com/williamvenner/fn_type_alias
- Owner: WilliamVenner
- License: mit
- Created: 2021-09-23T23:07:30.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2021-09-23T23:23:15.000Z (almost 5 years ago)
- Last Synced: 2024-10-11T11:34:01.819Z (over 1 year ago)
- Topics: alias, macro, proc-macro, proc-macro-attributes, rust, type
- Language: Rust
- Homepage: https://crates.io/crates/fn_type_alias
- Size: 2.93 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://crates.io/crates/fn_type_alias)
# ✨ `fn_type_alias`
A proc attribute macro that generates a type alias with the given identifier for the attributed function.
## Example
```rust
#[macro_use]
extern crate fn_type_alias;
#[type_alias(HelloWorldFn)] // The type alias will inherit its visibility from the function
pub(super) fn hello_world() {
println!("hello world!");
}
#[type_alias(pub(crate), HelloWorldFn)] // The type alias will be pub(crate), but the function will be pub
pub fn hello_world() {
println!("hello world!");
}
```
## Use Case
This macro is well suited for conditional compilation. For example, using the [`fn_abi`](https://crates.io/crates/fn_abi) macro:
```rust
#[macro_use]
extern crate fn_type_alias;
#[macro_use]
extern crate fn_abi;
#[abi(
linux32 = "C",
linux64 = "C",
win32 = "thiscall",
win64 = "stdcall"
)]
#[type_alias(HelloWorldFn)]
pub extern fn hello_world() {
println!("hello world!");
}
// Expands to when building for Windows 64-bit:
pub type HelloWorldFn = extern "stdcall" fn();
pub extern "stdcall" fn hello_world() {
println!("hello world!");
}
```