Last active
November 2, 2016 11:50
-
-
Save mzumi/b1512cfd084ac0e0cd3629c1a2621795 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#![feature(libc)] | |
extern crate libc; | |
use libc::*; | |
use std::ffi::{CStr, CString}; | |
#[repr(C)] | |
pub struct SampleStruct { | |
i: i32, | |
b: bool, | |
s: *const c_char | |
} | |
#[no_mangle] | |
pub extern fn create_sample_struct(s: *mut SampleStruct) { | |
unsafe { | |
(*s).i = 100; | |
(*s).b = false; | |
(*s).s = CString::new("hello").unwrap().into_raw(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment