使String类型与ARM兼容?

Phi*_*ide 4 arm rust

我需要为ARM设备编译程序.这似乎是失败的,也许是因为ARM上的类型差异?

unsafe { Ok(String::from(try!(CStr::from_ptr(buf.as_ptr() as *const i8).to_str()))) }
Run Code Online (Sandbox Code Playgroud)

错误是:

694 |         unsafe { Ok(String::from(try!(CStr::from_ptr(buf.as_ptr() as *const i8).to_str()))) }
    |                                                      ^^^^^^^^^^^^^^^^^^^^^^^^^ expected u8, found i8
    |
    = note: expected type `*const u8`
               found type `*const i8`
Run Code Online (Sandbox Code Playgroud)

什么是类型差异,我该如何解决?

Zal*_*ern 5

您可能想要使用std::os::raw::c_char而不是i8.(虽然这可能不是从中获取类型的正确位置.libc::c_char似乎也存在.)

基本问题是charC 中的类型可以根据平台进行签名或取消签名,并反映在外部函数接口中.理想情况下,您希望找到一种方法来进行转换,而无需明确提及类型.