Skip to content

TeaEntityLab/cstr

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

cstr

Build Status Docs

A macro for getting &'static CStr from literal.

This macro checks whether the given literal is valid for CStr at compile time, and returns a static reference of CStr.

Note that it currently cannot be used to initialize constants due to restriction of Rust.

Also, it currently only supports a UTF-8 string as input because Rust's tokenizer only accepts that without the b prefix. This may be expanded in the future if necessary.

Example

#[macro_use] extern crate cstr;
use std::ffi::CStr;

fn main() {
    let test = cstr!("hello");
    assert_eq!(test, CStr::from_bytes_with_nul(b"hello\0").unwrap());
}

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Rust 100.0%