z-jxy / rpkl

Pkl bindings for Rust
MIT License
3 stars 2 forks source link

Implement Deserialization for `Value` #2

Closed z-jxy closed 3 weeks ago

z-jxy commented 3 weeks ago

Currently deserialization for pkl_rs::Value is broken

Example pkl module:

ip = "127.0.0.1"
port = 8080

birds: Listing<String> = new {
  "Pigeon"
  "Hawk"
  "Penguin"
}

mapping = new Mapping {
  ["map_key"] = "map_value"
  ["map_key2"] = "map_value2"
}

Rust:

#[derive(serde::Deserialize, serde::Serialize, Debug)]
pub struct Example {
    pub ip: String,
    pub port: i64,
    pub birds: Vec<pkl_rs::Value>,
    pub mapping: pkl_rs::Value,
}

Results in the error for deserializing the mapping field:

Err(
    DeserializeError(
        "failed to deserialize: Message(\"invalid type: map, expected variant identifier\")",
    ),
)

and the following error for the bird field:

Err(
    DeserializeError(
        "failed to deserialize: Message(\"unknown variant `Pigeon`, expected one of `Map`, `List`, `String`, `Int`, `Boolean`, `Null`\")",
    ),
)

Still figuring out how to fix this. It seems for the Vec<pkl_rs::Value> case, the issue is when the SeqAccessImpl deserializer starting calling next_element_seed