まず、txtファイルに書き込まれているデータがあります。
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}}
上記の最終行を読み込んで、その中のデータの一つから処理を行いたい。
#[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(){
let f = File::open("hoge.txt").unwrap();
let reader = BufReader::new(f);
let lines = reader.lines();
let input_fn = lines.last().unwrap_or(Ok("".to_string())).unwrap();
let param:CharaParam = serde_json::from_str(&input_fn).unwrap();
println!("{:?}", param.Name);
}
Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.24s
Running `target/debug/sample`
“Apple”
おおおおおおおお、やりたいことは出来ているっぽい。ここが出来ると、あらゆることが可能になる!