Skip to content

Commit

Permalink
Stubbed out string module for tests during setup.
Browse files Browse the repository at this point in the history
  • Loading branch information
lorrenbiffin committed Apr 14, 2024
1 parent dc90f47 commit a89ab00
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 12 deletions.
3 changes: 2 additions & 1 deletion Cwrap.code-workspace
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"folders": [
{
"path": "."
"name": "Cwrap",
"path": ".",
}
],
"settings": {}
Expand Down
11 changes: 0 additions & 11 deletions core/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
}
}
2 changes: 2 additions & 0 deletions core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@

//--
pub mod error;

pub mod string;
12 changes: 12 additions & 0 deletions core/src/string.rs
Original file line number Diff line number Diff line change
@@ -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)),
}
}
3 changes: 3 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,7 @@
#![feature(error_in_core)] // </3

//--
pub use cwrap_core::string;
pub use cwrap_core::string::*;

pub use cwrap_core::error;

0 comments on commit a89ab00

Please sign in to comment.