#[derive(Serialize, Deserialize, Debug)] #[allow(non_snake_case)] struct Rotator { Pitch:f32, Roll:f32, Yaw:f32, } #[derive(Serialize, Deserialize, Debug)] #[allow(non_snake_case)] struct CharaParam { Name: String, Id: i32, ItemIdList: Vec<u32>, RotData: Rotator, } fn main() -> std::io::Result<()>{ let mut param = CharaParam{Name:String::from("Apple"), Id:0x01, ItemIdList:vec![1000, 1001], RotData:Rotator{Pitch:0.0, Roll:0.0, Yaw:32.0} }; let serialized: Vec<u8> = serde_json::to_vec(¶m).unwrap(); let mut fileRef = OpenOptions::new() .append(true) .open("hoge.txt") .expect("Unable to open file"); fileRef.write_all(&serialized).expect("write failed"); fileRef.write_all(b"\n").expect("write failed"); Ok(()) }
hoge.txt
{"Name":"Apple","Id":1,"ItemIdList":[1000,1001],"RotData":{"Pitch":0.0,"Roll":0.0,"Yaw":32.0}} {"Name":"Apple","Id":1,"ItemIdList":[1000,1001],"RotData":{"Pitch":0.0,"Roll":0.0,"Yaw":32.0}}
書き込みはなんかこれでOKっぽいけど、問題は読み込みやな。