< 返回版块

2019-06-10 00:37    责任编辑:jay

标签:rust

Tiny

The simple life is not simple.

// Tiny "Hello, World!" program in Rust.
#![feature(no_core, lang_items)]
#![no_std]
#![no_core]
#![no_main]

#[lang = "panic_info"]
struct PanicInfo {}
#[panic_handler]
fn panic(info: &PanicInfo) -> ! { loop {} }
#[lang = "eh_personality"]
extern fn eh_personality() {}
#[lang = "sized"]
trait Sized {}
#[lang = "copy"]
trait Copy {}
#[lang = "freeze"]
unsafe trait Freeze {}

#[link(name = "c")]
extern "C" {
    fn write(fd: i32, buf: *const i8, count: usize) -> isize;
    fn exit(status: i32) -> !;
}

#[no_mangle]
pub unsafe extern "C" fn main() -> ! {
    let s = b"Hello, World!\n";
    write(1, s as *const u8 as *const i8, 14);
    exit(0);
}

For x86_64-pc-windows-gnu in windows, line 20 #[link(name = "c")] should be deleted to compile correctly.