#别名 #类型 # #函数 #生成

fn_type_alias

一个进程属性宏,用于为属性函数生成具有给定标识符的类型别名

1 个不稳定版本

0.1.0 2021年9月23日

#77#别名

Download history 57/week @ 2024-03-11 39/week @ 2024-03-18 99/week @ 2024-03-25 98/week @ 2024-04-01 29/week @ 2024-04-08 30/week @ 2024-04-15 31/week @ 2024-04-22 22/week @ 2024-04-29 24/week @ 2024-05-06 31/week @ 2024-05-13 36/week @ 2024-05-20 28/week @ 2024-05-27 23/week @ 2024-06-03 91/week @ 2024-06-10 40/week @ 2024-06-17 26/week @ 2024-06-24

每月185次下载
用于 2 个包(通过 gmod

MIT 许可证

6KB
73

crates.io

fn_type_alias

一个进程属性宏,用于为属性函数生成具有给定标识符的类型别名。

示例

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

用例

此宏非常适合条件编译。例如,使用 fn_abi

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

依赖项

~1.5MB
~35K SLoC