【发布时间】:2024-04-20 02:50:01
【问题描述】:
我正在从文件中读取原始数据,我想将其转换为整数:
fn main() {
let buf: &[u8] = &[0, 0, 0, 1];
let num = slice_to_i8(buf);
println!("1 == {}", num);
}
pub fn slice_to_i8(buf: &[u8]) -> i32 {
unimplemented!("what should I do here?")
}
我会在 C 中进行强制转换,但在 Rust 中我该怎么做?
【问题讨论】: