From a89ab00ab0c73d29472392cc8835a1ab1499dc6d Mon Sep 17 00:00:00 2001 From: Lorren Biffin Date: Sun, 14 Apr 2024 14:40:45 -0700 Subject: [PATCH] Stubbed out string module for tests during setup. --- Cwrap.code-workspace | 3 ++- core/src/error.rs | 11 ----------- core/src/lib.rs | 2 ++ core/src/string.rs | 12 ++++++++++++ src/lib.rs | 3 +++ 5 files changed, 19 insertions(+), 12 deletions(-) create mode 100644 core/src/string.rs diff --git a/Cwrap.code-workspace b/Cwrap.code-workspace index 876a149..13cc302 100644 --- a/Cwrap.code-workspace +++ b/Cwrap.code-workspace @@ -1,7 +1,8 @@ { "folders": [ { - "path": "." + "name": "Cwrap", + "path": ".", } ], "settings": {} diff --git a/core/src/error.rs b/core/src/error.rs index a355ac4..3e4f752 100644 --- a/core/src/error.rs +++ b/core/src/error.rs @@ -24,14 +24,3 @@ pub enum CStringError { #[msg="utf-8 error: {:}"] Utf8Error(Utf8Error), } - -pub unsafe fn try_unwrap_cstr<'out>(bytes: *const i8) -> Result<&'out str, CStringError> { - if bytes.is_null() { - return Err(CStringError::Uninitialized); - } - - match CStr::from_ptr(bytes).to_str() { - Ok(c_str) => Ok(c_str), - Err(error) => Err(CStringError::Utf8Error(error)), - } -} diff --git a/core/src/lib.rs b/core/src/lib.rs index 13e6484..e149b9d 100644 --- a/core/src/lib.rs +++ b/core/src/lib.rs @@ -2,3 +2,5 @@ //-- pub mod error; + +pub mod string; diff --git a/core/src/string.rs b/core/src/string.rs new file mode 100644 index 0000000..e61f6fb --- /dev/null +++ b/core/src/string.rs @@ -0,0 +1,12 @@ + +/// TODO +pub unsafe fn try_unwrap_cstr<'out>(bytes: *const i8) -> Result<&'out str, CStringError> { + if bytes.is_null() { + return Err(CStringError::Uninitialized); + } + + match CStr::from_ptr(bytes).to_str() { + Ok(c_str) => Ok(c_str), + Err(error) => Err(CStringError::Utf8Error(error)), + } +} diff --git a/src/lib.rs b/src/lib.rs index e8f8907..36bd8b9 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -4,4 +4,7 @@ #![feature(error_in_core)] //