better_cstr

Crates.iobetter_cstr
lib.rsbetter_cstr
version0.2.1
created_at2025-04-24 20:37:15.627019+00
updated_at2025-04-26 09:46:58.367221+00
descriptionA better macro for working with C strings
homepage
repositoryhttps://github.com/iulian-rusu/better-cstr
max_upload_size
id1647902
size15,507
Iulian Rusu (iulian-rusu)

documentation

README

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.

Commit count: 3

cargo fmt