From 3ac7c9b298a5fcc3591a4dcb20f44fbacffc1128 Mon Sep 17 00:00:00 2001 From: peamaeq Date: Tue, 3 May 2022 15:27:05 +0800 Subject: [PATCH 1/2] 0503 --- src/utils.rs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/utils.rs b/src/utils.rs index c8c2a1d..73064b9 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -32,12 +32,10 @@ pub(crate) fn from_bstr(string: BSTR) -> String { } pub(crate) fn from_lpstr(string: LPCSTR) -> String { - unsafe { - let len = (0..).take_while(|&i| *string.offset(i) != 0).count(); + let len = unsafe { (0..).take_while(|&i| *string.offset(i) != 0).count() }; - let slice: &[u8] = std::slice::from_raw_parts(string.cast(), len); - std::str::from_utf8(slice).map(|s| s.to_owned()).unwrap() - } + let slice: &[u8] = unsafe { std::slice::from_raw_parts(string.cast(), len) }; + std::str::from_utf8(slice).map(|s| s.to_owned()).unwrap() } struct DefaultIncludeHandler {} From b0e9e3fce89267234e5624f840194cb4018589a3 Mon Sep 17 00:00:00 2001 From: peamaeq Date: Tue, 3 May 2022 18:51:53 +0800 Subject: [PATCH 2/2] 0503 --- src/utils.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/utils.rs b/src/utils.rs index 73064b9..d4171e0 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -32,10 +32,12 @@ pub(crate) fn from_bstr(string: BSTR) -> String { } pub(crate) fn from_lpstr(string: LPCSTR) -> String { - let len = unsafe { (0..).take_while(|&i| *string.offset(i) != 0).count() }; + let len = (0..) + .take_while(|&i| unsafe { *string.offset(i) } != 0) + .count(); let slice: &[u8] = unsafe { std::slice::from_raw_parts(string.cast(), len) }; - std::str::from_utf8(slice).map(|s| s.to_owned()).unwrap() + std::str::from_utf8(slice).unwrap().to_owned() } struct DefaultIncludeHandler {}