#c-str #string #macro #literals #string-literal

macro better_cstr

A better macro for working with C strings

3 unstable releases

new 0.2.1 Apr 26, 2025
0.2.0 Apr 25, 2025
0.1.0 Apr 24, 2025

#273 in FFI

Download history 126/week @ 2025-04-19

129 downloads per month

MIT license

6KB

Better CStr Macro

github crates.io docs.rs

Are you tired of writing .as_ptr() after all your C-string literals?

Simply use the c! macro:

use better_cstr::c;
use std::ffi::{c_char, CStr};

fn main() {
    let ptr: *const c_char = c!("Hello World");
    unsafe {
        println!("{:?}", CStr::from_ptr(ptr));
    }
}

Supports any kind of string literal that does not contain a null byte.

Dependencies

~195–620KB
~15K SLoC