Created
September 7, 2015 15:43
-
-
Save steveklabnik/18789c7d46b248dfcdb1 to your computer and use it in GitHub Desktop.
Issue with binding ownership and scopes in Rust
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
pub struct Command { | |
cmd: String, | |
} | |
impl Command { | |
pub fn new(cmd: &str) -> Command { | |
Command { | |
cmd: String::from(cmd), | |
} | |
} | |
} | |
#[no_mangle] | |
pub extern "C" fn command_new<'a>(cmd: *const libc::c_char) -> Command { | |
let buf_cmd = unsafe { CStr::from_ptr(cmd).to_bytes() }; | |
let str_cmd = String::from_utf8(buf_cmd.to_vec()).unwrap(); | |
Command::new(str_cmd) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment