terminated 1.0.0

Types for representing NUL-terminated UTF8 strings.
Documentation
  • Coverage
  • 100%
    8 out of 8 items documented4 out of 6 items with examples
  • Size
  • Source code size: 5.97 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 2.05 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 9s Average build duration of successful builds.
  • all releases: 9s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • SSheldon/terminated
    10 2 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • SSheldon

This crate provides types for representing NUL-terminated UTF8 strings.

The NulTerminatedStr type is useful when interacting with C APIs that require/guarantee UTF8 encoding. Rust has great support for dealing with UTF8, but C strings require a NUL terminator which Rust's str and String don't have.

let s = ntstr!("Hello, World!");

// You can use Rust's normal string operations
assert_eq!(s.find("World"), Some(7));

// And pass it to C since it's NUL-terminated
let ptr = s.as_ptr();

CStr vs NulTerminatedStr

The standard library does provide the CStr type that is NUL-terminated, but it does not use any specific encoding. It's therefore insufficient if your input needs to be both NUL-terminated and UTF8 encoded.