cxx icon indicating copy to clipboard operation
cxx copied to clipboard

char is not supported as function argument

Open alexeyr opened this issue 5 years ago • 5 comments

  error[cxxbridge]: unsupported type: char
     ┌─ tokenizers-cpp/pre_tokenizers.rs:56:52
     │
  56 │         fn char_delimiter_pre_tokenizer(delimiter: char) -> Box<PreTokenizer>;
     │                                                    ^^^^ unsupported type

Is the reason that some u32 values are not valid chars? If so, this could be specified in the error message.

alexeyr avatar Dec 23 '20 10:12 alexeyr

It seems consistent with rust::Str/String to add the class rust::Char with Char(char32_t) constructor throwing exception on an invalid value and an implicit operator char32_t().

alexeyr avatar Dec 23 '20 11:12 alexeyr

Hello @alexeyr,

I don't think char is supported, but I think you'd want std::os::raw::c_char instead. I think that will get translated into a char in C++ (although I haven't done it myself, yet).

I personally find looking at the cxx tests to be very helpful when looking for tested data type combinations. https://github.com/dtolnay/cxx/blob/master/tests/ffi/lib.rs

david-cattermole avatar Jan 03 '21 20:01 david-cattermole

@david-cattermole I was interested in going the other way around, wrapping existing Rust code using char (and expecting it to translate to char32_t). So my workaround it to use u32 in the bridge, and wrap/unwrap it manually.

alexeyr avatar Jan 04 '21 20:01 alexeyr

I would also be interested in having support for char

kraktus avatar Dec 23 '22 14:12 kraktus

~~cbdingen for instance support chars and use char => uint32_t conversion for the rust -> cpp side. For the cpp -> rust I think the simple fix of converting to char via char::from_u32(uint32_t).expect("Valid char") would enough for a first implementation. ~~

Edit: Now that c++11 is the minimal supported version, it should be trivial to map it to char32_t

kraktus avatar Dec 23 '22 14:12 kraktus