示例
#![feature(start, libc, lang_items)]
#![no_std]
#![no_main]
//libccrate允许从C导入函数。
extern crate libc;
//导入的C函数列表
extern {
pub fn printf(format: *const u8, ...) -> i32;
}
#[no_mangle]
//主函数,其输入参数被忽略,并返回退出状态
pub extern fn main(_nargs: i32, _args: *const *const u8) -> i32 {
// Print "Hello, World" to stdout using printf
unsafe {
printf(b"Hello, World!\n" as *const u8);
}
//退出,返回状态为0。
0
}
#[lang = "eh_personality"] extern fn eh_personality() {}
#[lang = "panic_fmt"] extern fn panic_fmt() -> ! { panic!() }