Last active
August 29, 2015 14:24
-
-
Save dnaeon/496cf15f0e02fd5dfacf to your computer and use it in GitHub Desktop.
test-rust-lib
This file contains hidden or 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
extern crate libc; | |
use std::{boxed, ffi, ptr}; | |
use libc::c_char; | |
#[repr(C)] | |
#[derive(Copy)] | |
pub struct Plugin { | |
key: *const c_char, | |
} | |
impl Clone for Plugin { | |
fn clone(&self) -> Self { *self } | |
} | |
impl Plugin { | |
pub fn new(key: Option<&str>) -> Plugin { | |
let c_key: *const c_char = match key { | |
Some(ref k) => ffi::CString::new(*k).unwrap().as_ptr(), | |
None => ptr::null(), | |
}; | |
Plugin { | |
key: c_key, | |
} | |
} | |
} | |
#[no_mangle] | |
pub extern fn get_plugins() -> boxed::Box<[Plugin]> { | |
let plugins = [ | |
Plugin::new(Some("my.plugin.foo")), | |
Plugin::new(Some("my.other.plugin.bar")), | |
Plugin::new(None), | |
]; | |
boxed::Box::new(plugins) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment