Add ToCStr method .with_c_str()

.with_c_str() is a replacement for the old .as_c_str(), to avoid
unnecessary boilerplate.

Replace all usages of .to_c_str().with_ref() with .with_c_str().
This commit is contained in:
Kevin Ballard 2013-08-14 19:21:59 -07:00
parent 48265b779f
commit 03ef71e262
33 changed files with 159 additions and 136 deletions

View file

@ -66,7 +66,7 @@ impl DynamicLibrary {
// T but that feature is still unimplemented
let maybe_symbol_value = do dl::check_for_errors_in {
do symbol.to_c_str().with_ref |raw_string| {
do symbol.with_c_str |raw_string| {
dl::symbol(self.handle, raw_string)
}
};
@ -145,7 +145,7 @@ mod dl {
use result::*;
pub unsafe fn open_external(filename: &path::Path) -> *libc::c_void {
do filename.to_c_str().with_ref |raw_name| {
do filename.with_c_str |raw_name| {
dlopen(raw_name, Lazy as libc::c_int)
}
}

View file

@ -29,7 +29,7 @@ pub fn fail_bounds_check(file: *c_char, line: size_t,
index: size_t, len: size_t) {
let msg = fmt!("index out of bounds: the len is %d but the index is %d",
len as int, index as int);
do msg.to_c_str().with_ref |buf| {
do msg.with_c_str |buf| {
fail_(buf, file, line);
}
}