You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
extern"C"{fnabsx(input:i32) -> i32;}fnmain(){let result = unsafe{absx(5)};println!("The absolute value of 5 is: {}", result);}// 链接到 C 库#[link(name = "absx")]extern{}
The text was updated successfully, but these errors were encountered:
宏
rust中以
!
结尾的函数基本都是宏,例如:print!
vec!
等。使用
macro_rules!
的声明(Declarative)
宏,和 三种过程(Procedural)
宏:声明宏
下面是
vec!
的简单定义和说明:vec![1,2,3]展开为:
定义一个test!可以生成常量,类似于reqwest中StatusCode中的宏status_codes!
调用C语言库
目录结构:
cargo new test
在Cargo.toml文件添加:
build.rs
absx.c文件:
src/main.rs
The text was updated successfully, but these errors were encountered: