Skip to content

Add CString cont. #549

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

Merged
merged 93 commits into from
Apr 15, 2025
Merged

Add CString cont. #549

merged 93 commits into from
Apr 15, 2025

Conversation

raviqqe
Copy link
Contributor

@raviqqe raviqqe commented Apr 7, 2025

This PR is a continued work of #342, the heapless implementation of alloc::ffi::CString. Credits to @vrmiguel.

Closes #330.

Notable changes from the previous PR

  • Implement Deref<Target = CStr> for CString.
    • As well as Default, AsRef, Borrow, PartialEq, Eq, PartialOrd, and Ord
  • Remove the len and as_str_unchecked associated functions that should be implemented in the upstream of core::ffi::CStr.
  • Rename the push_bytes associated function extend_from_bytes.
    • This change is to align the nominology with heapless::Vec.

Future work

  • heapless::String interoperability
    • CString::into_string
  • heapless::Vec interoperability
    • CString::from_vec_with_nul
    • CString::into_bytes
    • CString::into_bytes_with_nul

src/c_string.rs Outdated
///
/// assert_eq!(cstr.to_str(), Ok("hey there"));
/// ```
pub fn push_bytes(&mut self, bytes: &[u8]) -> Result<(), CapacityError> {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should we rename this extend_from_bytes or extend_from_slice?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I renamed it extend_from_bytes for now. extend_from_slice is a bit ambiguous because it might mean either byte or CStr slices.

@reitermarkus reitermarkus requested a review from a team April 8, 2025 21:39
@raviqqe raviqqe requested a review from vrmiguel April 9, 2025 04:53
Copy link
Contributor

@vrmiguel vrmiguel left a comment

Choose a reason for hiding this comment

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

Awesome stuff @raviqqe !

@raviqqe raviqqe requested a review from reitermarkus April 10, 2025 23:26
@reitermarkus reitermarkus enabled auto-merge April 15, 2025 19:41
@reitermarkus reitermarkus added this pull request to the merge queue Apr 15, 2025
@reitermarkus
Copy link
Member

Thanks!

Merged via the queue into rust-embedded:main with commit ad5a0ee Apr 15, 2025
22 checks passed
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?
3 participants