|
6 | 6 | clippy::unnecessary_wraps |
7 | 7 | )] |
8 | 8 |
|
| 9 | +pub mod cast; |
9 | 10 | pub mod module; |
10 | 11 |
|
11 | 12 | use cxx::{CxxString, CxxVector, UniquePtr}; |
12 | 13 | use std::fmt::{self, Display}; |
| 14 | +use std::os::raw::c_char; |
13 | 15 |
|
14 | 16 | #[cxx::bridge(namespace = "tests")] |
15 | 17 | pub mod ffi { |
@@ -81,7 +83,7 @@ pub mod ffi { |
81 | 83 | fn c_return_ref(shared: &Shared) -> &usize; |
82 | 84 | fn c_return_mut(shared: &mut Shared) -> &mut usize; |
83 | 85 | fn c_return_str(shared: &Shared) -> &str; |
84 | | - fn c_return_sliceu8(shared: &Shared) -> &[u8]; |
| 86 | + fn c_return_slice_char(shared: &Shared) -> &[c_char]; |
85 | 87 | fn c_return_mutsliceu8(slice: &mut [u8]) -> &mut [u8]; |
86 | 88 | fn c_return_rust_string() -> String; |
87 | 89 | fn c_return_unique_ptr_string() -> UniquePtr<CxxString>; |
@@ -110,7 +112,7 @@ pub mod ffi { |
110 | 112 | fn c_take_ref_r(r: &R); |
111 | 113 | fn c_take_ref_c(c: &C); |
112 | 114 | fn c_take_str(s: &str); |
113 | | - fn c_take_sliceu8(s: &[u8]); |
| 115 | + fn c_take_slice_char(s: &[c_char]); |
114 | 116 | fn c_take_slice_shared(s: &[Shared]); |
115 | 117 | fn c_take_rust_string(s: String); |
116 | 118 | fn c_take_unique_ptr_string(s: UniquePtr<CxxString>); |
@@ -214,7 +216,7 @@ pub mod ffi { |
214 | 216 | fn r_take_ref_r(r: &R); |
215 | 217 | fn r_take_ref_c(c: &C); |
216 | 218 | fn r_take_str(s: &str); |
217 | | - fn r_take_sliceu8(s: &[u8]); |
| 219 | + fn r_take_slice_char(s: &[c_char]); |
218 | 220 | fn r_take_rust_string(s: String); |
219 | 221 | fn r_take_unique_ptr_string(s: UniquePtr<CxxString>); |
220 | 222 | fn r_take_ref_vector(v: &CxxVector<u8>); |
@@ -472,8 +474,9 @@ fn r_take_rust_string(s: String) { |
472 | 474 | assert_eq!(s, "2020"); |
473 | 475 | } |
474 | 476 |
|
475 | | -fn r_take_sliceu8(s: &[u8]) { |
| 477 | +fn r_take_slice_char(s: &[c_char]) { |
476 | 478 | assert_eq!(s.len(), 5); |
| 479 | + let s = cast::c_char_to_unsigned(s); |
477 | 480 | assert_eq!(std::str::from_utf8(s).unwrap(), "2020\0"); |
478 | 481 | } |
479 | 482 |
|
|
0 commit comments