cstr-argument
A trait for converting function arguments to null terminated strings
Documentation
Usage
Add this to your Cargo.toml
:
[dependencies]
cstr-argument = "0.0.1"
and this to your crate root:
extern crate cstr_argument;
Example
use std::os::raw::c_char;
use cstr_argument::CStrArgument;
extern "C" {
fn foo(s: *const c_char);
}
fn bar<S: CStrArgument>(s: S) {
let s = s.into_cstr().expect("argument contained interior nulls");
unsafe {
foo(s.as_ref().as_ptr())
}
}
fn baz() {
bar("hello "); bar("world\0"); bar("!".to_owned()); }