Skip to content

Instantly share code, notes, and snippets.

@steveklabnik
Forked from jefftime/main.rs
Last active January 16, 2018 13:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save steveklabnik/5abd59a8fe7e5abda3db58bd8c208fbb to your computer and use it in GitHub Desktop.
Save steveklabnik/5abd59a8fe7e5abda3db58bd8c208fbb 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 rust_panic_fmt() -> ! { unsafe { abort() } }
#[lang = "eh_personality"]
#[no_mangle]
pub extern fn rust_eh_personality() {}
#[lang = "eh_unwind_resume"]
#[no_mangle]
pub extern fn rust_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