On this page
  1. CString
  2. Signature & Overview
  3. Notes & Pitfalls
  4. Example

CString

Prev: ffi | Up: ffi | Next: `extern_C`
Rel: ffi, rust/builtins
Ref: Rust std — CString
Tags: #public #prog #rust #stdlib #ffi #tier/specialized


Signature & Overview

CString (owned)  |  &CStr (borrowed)

NUL-terminated byte strings without interior NUL bytes for exchanging strings across the C ABI.

Notes & Pitfalls

Example

use std::ffi::{CStr, CString};

fn main() {
    let c_str = CString::new("hello ffi").expect("no interior NUL");
    let borrowed: &CStr = c_str.as_c_str();
    assert_eq!(borrowed.to_str().unwrap(), "hello ffi");
}

Linked from

Related notes