Crates.io | literal_cstr |
lib.rs | literal_cstr |
version | 0.1.1 |
source | src |
created_at | 2018-08-18 16:11:35.963974 |
updated_at | 2018-10-07 17:26:54.044624 |
description | A macro that makes it easier to create literal C strings |
homepage | |
repository | https://github.com/hjr3/literal_cstr |
max_upload_size | |
id | 80080 |
size | 15,766 |
A procedural macro for making literal C strings.
I was tired of typing the following:
let s = CString::new("Hello, world!").unwrap();
Ideally, I would be able to do something similar to the syntax of a byte string c"Hello, world!"
but that requires a language change.
I decided to create a macro that is close enough.
let s = c!("Hello, world!");
Currently requires a nightly build of rust. Use rustc 1.31.0-nightly (4efdc04a5 2018-10-06)
or newer.
[dependencies]
literal_cstr = "0.1"
#![feature(proc_macro_hygiene)]
extern crate literal_cstr;
use literal_cstr::c;
Procedural macros are stable, but #![feature(proc_macro_hygiene)]
is required in order to use the macro with a literal string expression.
let s = c!("Hello, world!");
Check out /examples/show.rs for a full example.
$ cargo test
Licensed under either of
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.