Crates.io | c8str |
lib.rs | c8str |
version | 0.2.1 |
created_at | 2024-07-22 17:12:38.756342+00 |
updated_at | 2025-08-11 15:43:04.177984+00 |
description | String types that are both utf-8 and null terminated |
homepage | |
repository | https://codeberg.org/maia/c8str-rs |
max_upload_size | |
id | 1311401 |
size | 69,731 |
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:
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 C8String
s.
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");
alloc
- Enable the C8String
type. This requires the standard alloc
or std
crates.0.2.1:
c8format
macro0.2.0:
c8format
macroWithC8Str
traitC8String::new
to take no args and create an empty string without allocatingIndex<RangeFrom<usize>>
for C8Str
0.1.2
C8Str::from_ptr[_unchecked]
const0.1.1
0.1.0