c8str 0.2.1

String types that are both utf-8 and null terminated
Documentation
  • Coverage
  • 100%
    20 out of 20 items documented2 out of 10 items with examples
  • Size
  • Source code size: 69.22 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 6.88 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 11s Average build duration of successful builds.
  • all releases: 11s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Repository
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • maia-s

c8str

This crate provides the C8Str and C8String types, which combine the properties of Rust native utf-8 strings and C style null terminated strings. These types guarantee that:

  • The string is valid utf-8
  • The string ends with a null terminator
  • The string doesn't contain any null bytes before the end

Both types provide methods to get references to both &str (with or without the null terminator) and &CStr, or a pointer to *const c_char. They dereference to &str without the null terminator.

The c8 macro creates compile time constants of type &C8Str from string literals. The c8string macro creates a C8String verified at compile time, and the c8format macro can format into C8Strings.

The WithC8Str trait provides a convenience method for accessing an object as a &C8Str.

C8Str is no_std compatible. C8String is available behind the alloc feature.

# use c8str::c8;
assert_eq!(c8!("hello").as_str(), "hello");
assert_eq!(c8!("hello").as_c_str(), c"hello");

Features

  • alloc - Enable the C8String type. This requires the standard alloc or std crates.

Recent changes

  • 0.2.1:

    • Fix c8format macro
  • 0.2.0:

    • Add c8format macro
    • Add WithC8Str trait
    • Add some methods
    • Change C8String::new to take no args and create an empty string without allocating
    • Impl Index<RangeFrom<usize>> for C8Str
    • MSRV 1.81
  • 0.1.2

    • Make C8Str::from_ptr[_unchecked] const
  • 0.1.1

    • Show documentation for all features on docs.rs
  • 0.1.0

    • First release