Skip to content

Instantly share code, notes, and snippets.

@jefftime
Last active January 16, 2018 13:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jefftime/d7e96461138b5aa6895550b63caac66c to your computer and use it in GitHub Desktop.
Save jefftime/d7e96461138b5aa6895550b63caac66c to your computer and use it in GitHub Desktop.
#![feature(lang_items, start)]
#![no_std]
#[link(name = "c")]
extern {
fn puts(s: *const u8) -> isize;
fn abort() -> !;
}
#[lang = "panic_fmt"]
#[no_mangle]
pub extern fn panic_fmt() -> ! { unsafe { abort() } }
#[lang = "eh_personality"]
#[no_mangle]
pub extern fn eh_personality() {}
#[lang = "eh_unwind_resume"]
#[no_mangle]
pub extern fn eh_unwind_resume() {}
struct MyType {
integer: i32
}
impl MyType {
pub fn new(flag: bool) -> Result<MyType, ()> {
if flag { Ok(MyType { integer: 5 }) } else { Err(()) }
}
}
#[start]
fn main(_argc: isize, _argv: *const *const u8) -> isize {
unsafe { puts(b"Hello, world\0" as *const u8); }
let s = MyType::new(true).unwrap();
0
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment