Skip to content

Instantly share code, notes, and snippets.

@steveklabnik
Created September 7, 2015 15:43
Show Gist options
  • Save steveklabnik/18789c7d46b248dfcdb1 to your computer and use it in GitHub Desktop.
Save steveklabnik/18789c7d46b248dfcdb1 to your computer and use it in GitHub Desktop.
Issue with binding ownership and scopes in Rust
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