Added the documentation about length to CString::from_raw

This commit is contained in:
Alexis Bourget
2020-06-03 23:32:26 +02:00
parent eeaf497b2a
commit 00a7b56bab
+6
View File
@@ -395,6 +395,12 @@ pub unsafe fn from_vec_unchecked(mut v: Vec<u8>) -> CString {
/// ownership of a string that was allocated by foreign code) is likely to lead
/// to undefined behavior or allocator corruption.
///
/// It should be noted that the length isn't just "recomputed," but that
/// the recomputed length must match the original length from the
/// [`into_raw`] call. This means the [`into_raw`]/`from_raw` methods
/// should not be used when passing the string to C functions that can
/// modify the string's length.
///
/// > **Note:** If you need to borrow a string that was allocated by
/// > foreign code, use [`CStr`]. If you need to take ownership of
/// > a string that was allocated by foreign code, you will need to