]> git.lizzy.rs Git - rust.git/blob - example/alloc_example.rs
Rollup merge of #90102 - nbdd0121:box3, r=jonas-schievink
[rust.git] / example / alloc_example.rs
1 #![feature(start, core_intrinsics, alloc_error_handler, box_syntax)]
2 #![no_std]
3
4 extern crate alloc;
5 extern crate alloc_system;
6
7 use alloc::boxed::Box;
8
9 use alloc_system::System;
10
11 #[global_allocator]
12 static ALLOC: System = System;
13
14 #[cfg_attr(unix, link(name = "c"))]
15 #[cfg_attr(target_env = "msvc", link(name = "msvcrt"))]
16 extern "C" {
17     fn puts(s: *const u8) -> i32;
18 }
19
20 #[panic_handler]
21 fn panic_handler(_: &core::panic::PanicInfo) -> ! {
22     core::intrinsics::abort();
23 }
24
25 #[alloc_error_handler]
26 fn alloc_error_handler(_: alloc::alloc::Layout) -> ! {
27     core::intrinsics::abort();
28 }
29
30 #[start]
31 fn main(_argc: isize, _argv: *const *const u8) -> isize {
32     let world: Box<&str> = box "Hello World!\0";
33     unsafe {
34         puts(*world as *const str as *const u8);
35     }
36
37     0
38 }