-
Notifications
You must be signed in to change notification settings - Fork 193
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add CString
#342
base: main
Are you sure you want to change the base?
Add CString
#342
Conversation
/// | ||
/// Stores up to N-1 elements with a byte reserved for the terminating nil byte. | ||
#[derive(Clone)] | ||
pub struct CString<const CAP: usize> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pub struct CString<const CAP: usize> { | |
pub struct CString<const N: usize> { |
to be consistent with the other types.
/// ); | ||
/// ``` | ||
#[inline] | ||
pub fn as_bytes_with_null(&self) -> &[u8] { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pub fn as_bytes_with_null(&self) -> &[u8] { | |
pub fn as_bytes_with_nul(&self) -> &[u8] { |
to be consistent with std
.
/// Ok("heapless") | ||
/// ); | ||
/// ``` | ||
pub fn to_str(&self) -> Result<&str, core::str::Utf8Error> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Implement Deref<Target = CStr>
instead to get this automatically.
} | ||
|
||
/// | ||
pub fn as_ptr(&self) -> *const u8 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Implement Deref<Target = CStr>
instead to get this automatically.
} | ||
|
||
/// TODO | ||
pub fn as_mut_ptr(&mut self) -> *mut u8 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
std::ffi::CString
only has into_raw
.
@vrmiguel, do you still plan on working on this? |
@reitermarkus If @vrmiguel is busy, maybe can someone take over this work? I'm also interested in this feature and wouldn't mind to help making changes. |
This PR is still in draft but feel free to review or comment on it
Closes #330