mirror of
https://codeberg.org/icewind/vdf-reader.git
synced 2026-06-03 10:04:08 +02:00
fix unit enum parse
This commit is contained in:
parent
bc68a8c3a1
commit
988672437c
3 changed files with 22 additions and 12 deletions
12
src/serde.rs
12
src/serde.rs
|
|
@ -436,7 +436,7 @@ impl<'de, 'a> de::Deserializer<'de> for &'a mut Deserializer<'de> {
|
||||||
.visit_enum(Enum::new(self))
|
.visit_enum(Enum::new(self))
|
||||||
.map_err(|e| match (variant_token, &e) {
|
.map_err(|e| match (variant_token, &e) {
|
||||||
(Some(variant_token), VdfError::UnknownVariant(_)) => {
|
(Some(variant_token), VdfError::UnknownVariant(_)) => {
|
||||||
e.with_source_span(variant_token.span, self.source())
|
e.with_source_span(variant_token.span.start..self.last_span.end, self.source())
|
||||||
}
|
}
|
||||||
_ => e,
|
_ => e,
|
||||||
})
|
})
|
||||||
|
|
@ -662,10 +662,6 @@ impl<'a, 'de> Enum<'a, 'de> {
|
||||||
fn new(de: &'a mut Deserializer<'de>) -> Self {
|
fn new(de: &'a mut Deserializer<'de>) -> Self {
|
||||||
Enum { de }
|
Enum { de }
|
||||||
}
|
}
|
||||||
|
|
||||||
fn source(&self) -> &'de str {
|
|
||||||
self.de.source()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// `EnumAccess` is provided to the `Visitor` to give it the ability to determine
|
// `EnumAccess` is provided to the `Visitor` to give it the ability to determine
|
||||||
|
|
@ -692,12 +688,6 @@ impl<'de, 'a> VariantAccess<'de> for Enum<'a, 'de> {
|
||||||
type Error = VdfError;
|
type Error = VdfError;
|
||||||
|
|
||||||
fn unit_variant(self) -> Result<()> {
|
fn unit_variant(self) -> Result<()> {
|
||||||
let (str, span) = self.de.read_str()?;
|
|
||||||
|
|
||||||
if !str.is_empty() {
|
|
||||||
return Err(SerdeParseError::new("unit", str.as_ref(), span, self.source()).into());
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -56,7 +56,7 @@ enum Expected {
|
||||||
},
|
},
|
||||||
Sprite {
|
Sprite {
|
||||||
#[serde(rename = "$spriteorientation")]
|
#[serde(rename = "$spriteorientation")]
|
||||||
sprite_orientation: String,
|
sprite_orientation: SpriteOrientation,
|
||||||
#[serde(rename = "$spriteorigin")]
|
#[serde(rename = "$spriteorigin")]
|
||||||
sprite_origin: [f32; 2],
|
sprite_origin: [f32; 2],
|
||||||
#[serde(rename = "$basetexture")]
|
#[serde(rename = "$basetexture")]
|
||||||
|
|
@ -66,6 +66,16 @@ enum Expected {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
|
||||||
|
#[serde(rename_all = "snake_case")]
|
||||||
|
pub enum SpriteOrientation {
|
||||||
|
ParallelUpright,
|
||||||
|
#[default]
|
||||||
|
VpParallel,
|
||||||
|
Oriented,
|
||||||
|
VpParallelOriented,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
#[serde(untagged)]
|
#[serde(untagged)]
|
||||||
enum SingleOrTriple<T> {
|
enum SingleOrTriple<T> {
|
||||||
|
|
|
||||||
10
tests/snapshots/serde__tests__data__game_text.vmt.snap
Normal file
10
tests/snapshots/serde__tests__data__game_text.vmt.snap
Normal file
|
|
@ -0,0 +1,10 @@
|
||||||
|
---
|
||||||
|
source: tests/serde.rs
|
||||||
|
expression: result
|
||||||
|
---
|
||||||
|
Sprite(
|
||||||
|
r#$spriteorientation: vp_parallel,
|
||||||
|
r#$spriteorigin: (0.5, 0.5),
|
||||||
|
r#$basetexture: "editor/game_text",
|
||||||
|
r#$no_fullbright: true,
|
||||||
|
)
|
||||||
Loading…
Add table
Add a link
Reference in a new issue