Skip to content
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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft

Add CString #342

wants to merge 1 commit into from

Conversation

vrmiguel
Copy link

@vrmiguel vrmiguel commented Jan 31, 2023

This PR is still in draft but feel free to review or comment on it

Closes #330

///
/// Stores up to N-1 elements with a byte reserved for the terminating nil byte.
#[derive(Clone)]
pub struct CString<const CAP: usize> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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] {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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> {
Copy link
Member

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 {
Copy link
Member

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 {
Copy link
Member

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.

@reitermarkus
Copy link
Member

@vrmiguel, do you still plan on working on this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Is there interest for heapless::CString?
2 participants