#alias #type #macro #function #generate

macro fn_type_alias

A proc attribute macro that generates a type alias with the given identifier for the attributed function

1 unstable release

0.1.0 Sep 23, 2021

#93 in #alias

Download history 22/week @ 2024-11-17 22/week @ 2024-11-24 32/week @ 2024-12-01 54/week @ 2024-12-08 50/week @ 2024-12-15 2/week @ 2024-12-22 2/week @ 2024-12-29 24/week @ 2025-01-05 31/week @ 2025-01-12 40/week @ 2025-01-19 15/week @ 2025-01-26 41/week @ 2025-02-02 36/week @ 2025-02-09 30/week @ 2025-02-16 46/week @ 2025-02-23 21/week @ 2025-03-02

140 downloads per month
Used in 2 crates (via gmod)

MIT license

6KB
73 lines

crates.io

fn_type_alias

A proc attribute macro that generates a type alias with the given identifier for the attributed function.

Example

#[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 macro:

#[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!");
}

Dependencies

~1.5MB
~38K SLoC