Skip to content

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

Open
@rlidwka

Description

@rlidwka

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"`

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions