cstr-argument

A trait for converting function arguments to null terminated strings

Build Status Version

Documentation

Usage

Add this to your Cargo.toml:

toml [dependencies] cstr-argument = "0.0.1"

and this to your crate root:

rust extern crate cstr_argument;

Example

```rust use std::os::raw::cchar; use cstrargument::CStrArgument;

extern "C" { fn foo(s: *const c_char); }

fn bar(s: S) { let s = s.intocstr().expect("argument contained interior nulls"); unsafe { foo(s.asref().as_ptr()) } }

fn baz() { bar("hello "); // Argument will be converted to a CString requiring an allocation bar("world\0"); // Argument will be converted to a CStr without allocation bar("!".to_owned()); // Argument will be converted to a CString possibly requiring an allocation } ```