str/str.rs
1extern crate cbox;
2extern crate libc;
3
4use cbox::CBox;
5
6static PRINT_TEXT:&'static [u8] = b"%s\n\0";
7
8extern {
9 fn printf(fmt: *const u8, text: *mut libc::c_char);
10}
11
12extern fn steal_print(text: *mut libc::c_char) {
13 unsafe {
14 printf(PRINT_TEXT.as_ptr(), text);
15 libc::free(text as *mut libc::c_void);
16 }
17}
18
19fn main() {
20 unsafe {
21 let text = CBox::from("Hello, world!");
22 steal_print(text.unwrap());
23 }
24}