Closed butterflyhigh closed 10 months ago
I was not able to reproduce this. After fixing the type of ustx_version
from f32 to String, it deserializes correctly into:
UstxFile {
name: "New Project",
comment: "",
output_dir: "Vocal",
cache_dir: "UCache",
ustx_version: "0.6",
resolution: 480,
bpm: 120,
beat_per_bar: 4,
}
If you are stuck getting the same thing to work, I would recommend taking your issue to any of the resources shown in https://www.rust-lang.org/community. This library is one of the most widely used Rust libraries and plenty of people will be able to provide guidance about it.
I think I truncated out whatever was causing the error by accident. When I just use the shortened version, it works fine. Sorry about that.
The full file:
The full struct(s):
#[derive(Deserialize, Debug)]
struct UstxFile {
name: String,
comment: String,
output_dir: String,
cache_dir: String,
ustx_version: String,
resolution: isize,
bpm: isize,
beat_per_bar: isize,
beat_unit: isize,
expressions: Vec<Expression>,
exp_selectors: Vec<String>,
exp_primary: isize,
exp_secondary: isize,
key: isize,
time_signatures: Vec<TimeSig>,
tempos: Vec<Tempo>,
tracks: Vec<Track>
}
#[derive(Deserialize, Debug)]
struct Part {
name: String,
comment: String,
track_no: isize,
position: isize,
}
#[derive(Deserialize, Debug)]
struct Note {
position: isize,
duration: isize,
tone: isize,
lyric: String,
pitch: PitchData,
vibrato: Vibrato,
phoneme_expressions: Vec<PhonemeExpression>
}
#[derive(Deserialize, Debug)]
struct PhonemeOverride {
index: usize,
overlap_delta: f64
}
#[derive(Deserialize, Debug)]
struct PhonemeExpression {
index: usize,
abbr: String,
value: isize
}
#[derive(Deserialize, Debug)]
struct Vibrato {
length: isize,
period: isize,
depth: isize,
fade_in: isize,
fade_out: isize,
shift: isize,
drift: isize,
vol_link: isize
}
#[derive(Deserialize, Debug)]
struct Pitch {
data: Vec<PitchData>,
snap_first: bool
}
#[derive(Deserialize, Debug)]
struct PitchData {
x: f64,
y: f64,
shape: String
}
#[derive(Deserialize, Debug)]
struct Track {
singer: String,
phonemizer: String,
renderer_settings: RendererSettings,
track_name: String,
track_color: String,
mute: bool,
solo: bool,
volume: f64,
pan: f64,
voice_color_names: Vec<String>
}
#[derive(Deserialize, Debug)]
struct RendererSettings {
}
#[derive(Deserialize, Debug)]
struct Expression {
name: String,
abbr: String,
value_type: String, // change this to enum
min: isize,
max: isize,
default_value: isize,
is_flag: bool,
flag: String
}
#[derive(Deserialize, Debug)]
struct TimeSig {
bar_position: isize,
beat_per_bar: isize,
beat_unit: isize,
}
#[derive(Deserialize, Debug)]
struct Tempo {
position: isize,
bpm: isize
}
Apologies for the confusion/
I am trying to deserialize a YAML file into a struct.
The YAML file (it's long, and the problem appears on line 1, so I truncated it):
The struct:
The error message:
Error: Error("missing field
comment", line: 1, column: 2)
I submitted the file into yamllint.com, and it seems to be a valid YAML file, so I believe this is a bug. Thank you for your time.