So, if i understand correctly, using CString::new with 'false' as a
second argument implies :
- as you have no control on the lifetime underlying buffer, generally,
you have to as_str() and clone() the CString (the exception is when
you use immediately (right after creation) and only once the CString,
for example to display it)
- it better to write
value = unsafe { let tmp = CString::new(...., false); if
tmp.is_not_null {tmp_str = tmp .as_str()}; tmp_str.clone() }
to avoid any misused of a possibly transient CString
than
let tmp = unsafe { CString::new(...., false) };
value = if tmp.is_not_null {let tmp_str = tmp .as_str()}; tmp_str.clone() }Thanks 2014-05-13 1:24 GMT+02:00 comex <[email protected]>: > On Mon, May 12, 2014 at 6:41 PM, Christophe Pedretti > <[email protected]> wrote: >> Another SQLite function, sqlite3_column_text, return a *c_uchar; so, >> tu use the CString new, which takes a *c_char as argument, i can cast >> CString::new(sqlite3_column_text(pStmt, column_index) as *i8, false) >> >> But is it correct ? > > Looks correct, but note that this doesn't copy any data by itself; if > the original pointer becomes invalid, which happens in various > situations documented by the SQLite API, so will the CString. _______________________________________________ Rust-dev mailing list [email protected] https://mail.mozilla.org/listinfo/rust-dev
