Skip to content

Commit 1b32b38

Browse files
committed
Rename unwrap functions to into_inner
Apply conventions described in [Rust RFC 430][rfc] where `unwrap` is reserved for panicing methods. [rfc]: rust-lang/rfcs#430
1 parent afc5e00 commit 1b32b38

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

src/c_str.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -294,12 +294,12 @@ impl CStrBuf {
294294

295295
/// Unwraps the wrapped `*libc::c_char` from the `CStrBuf` wrapper
296296
/// without running the destructor. If the string was allocated,
297-
/// a user of `.unwrap()` should ensure the allocation is eventually
297+
/// a user of `.into_inner()` should ensure the allocation is eventually
298298
/// freed.
299299
///
300300
/// Prefer `.as_ptr()` when just retrieving a pointer to the
301301
/// string data, as that does not relinquish ownership.
302-
pub unsafe fn unwrap(mut self) -> *const libc::c_char {
302+
pub unsafe fn into_inner(mut self) -> *const libc::c_char {
303303
self.dtor = None;
304304
self.ptr
305305
}
@@ -438,13 +438,13 @@ impl CString {
438438

439439
/// Unwraps the raw character pointer from the `CString`
440440
/// without running the destructor. If the string was allocated,
441-
/// a user of `.unwrap()` should ensure the allocation is eventually
441+
/// a user of `.into_inner()` should ensure the allocation is eventually
442442
/// freed.
443443
///
444444
/// Prefer `.as_ptr()` when just retrieving a pointer to the
445445
/// string data, as that does not relinquish ownership.
446-
pub unsafe fn unwrap(self) -> *const libc::c_char {
447-
self.buf.unwrap()
446+
pub unsafe fn into_inner(self) -> *const libc::c_char {
447+
self.buf.into_inner()
448448
}
449449

450450
/// Return the number of bytes in the CString
@@ -1094,9 +1094,9 @@ mod tests {
10941094
}
10951095

10961096
#[test]
1097-
fn test_unwrap() {
1097+
fn test_into_inner() {
10981098
let c_str = "hello".to_c_str();
1099-
unsafe { libc::free(c_str.unwrap() as *mut libc::c_void) }
1099+
unsafe { libc::free(c_str.into_inner() as *mut libc::c_void) }
11001100
}
11011101

11021102
#[test]

0 commit comments

Comments
 (0)