Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support 'pub const BAR: &CStr = c"hello world";' #927

Open
rlidwka opened this issue Feb 10, 2024 · 3 comments
Open

Support 'pub const BAR: &CStr = c"hello world";' #927

rlidwka opened this issue Feb 10, 2024 · 3 comments

Comments

@rlidwka
Copy link

rlidwka commented Feb 10, 2024

We have C string literals now stabilized in Rust since rust-lang/rust#105723 (since v1.77.0, which'll be released next month).

It seems reasonable to have const string literals like these:

use std::ffi::CStr;
pub const BAR: &CStr = c"hello world";

and convert them to #define or constexpr or whatever cbindgen usually does with constants

Current behavior is very much not ideal (probably need to update syn to v2?):

$ cbindgen --lang C
thread 'main' panicked at /home/user/.cargo/registry/src/index.crates.io-6f17d22bba15001f/syn-1.0.109/src/lit.rs:1020:13:
Unrecognized literal: `c"hello world"`
@rlidwka
Copy link
Author

rlidwka commented Feb 10, 2024

actually, that's not supported yet in syn: dtolnay/syn#1502

@emilio
Copy link
Collaborator

emilio commented Apr 14, 2024

Seems like sending a PR to syn would be the way to go, then once that's merged we can use it...

@rlidwka
Copy link
Author

rlidwka commented Apr 15, 2024

Seems like sending a PR to syn would be the way to go, then once that's merged we can use it...

looks like it's already merged:
dtolnay/syn#1622

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants