0
我到一個數組序列兩個值,我試圖去通過WriteBuf但我得到的錯誤是如何從陣列
error: the trait `std::io::Write` is not implemented for the type `[_; 12]`
error: type `std::io::buffered::BufWriter<&mut [_; 12]>` does not implement any method in scope named `write_be_u32`
error: type `std::io::buffered::BufWriter<&mut [_; 12]>` does not implement any method in scope named `write_be_f64`
這裏是最少的代碼生成此錯誤打造WriteBuf :
use std::io::{ BufWriter, Write };
fn main(){
let packed_data = [0; 12];
let timestamp : u32 = 100;
let value : f64 = 9.9;
let writer = BufWriter::new(&mut packed_data);
writer.write_be_u32(timestamp);
writer.write_be_f64(value);
println!("Packed data looks like {:?}", packed_data);
}
我沒有正確借用切片?我注意到使用適當的模塊來爲我的緩衝區定義Write
特徵嗎?
下面是該代碼的圍欄:http://is.gd/ol8qND
我在描述我的代碼問題時並不完整。你解決了第一個錯誤(我列出的),以滿足特性'std :: io :: Write',但我想使用'write_be_u32' /'write_be_f64',這些都不起作用。我將更新這些錯誤的帖子。 – xrl
@xrl:我相信已經從Rust標準庫中刪除了實現這些方法的'Writer'特徵。所以你可能在這方面運氣不好。 – Adrian
艾德里安好抓!我不確定我是如何看到那些舊文檔的,並沒有意識到它是舊的。 – xrl