Skip to content

Handle &CStr <-> const char* #681

@dtolnay

Description

@dtolnay

For a C++ function like this:

void example(const char *s);

it should work to call it as:

use std::ffi::CStr;

#[cxx::bridge]
mod ffi {
    unsafe extern "C++" {
        fn example(s: &CStr);
    }
}

fn main() {
    let cstr = CStr::from_bytes_with_nul(b"test\0").unwrap();
    ffi::example(cstr);
}

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions