Closed jess-sol closed 2 years ago
Thank you for looking into this! However, I've tentatively decided not to pursue this functionality for now. Value
is a driver primitive that doesn't map cleanly onto serde's data types. One can fairly easily derive serde's traits on their own structs, and populate their fields using this driver (or a higher-level lib/OGM), e.g.
#[derive(Serialize, Deserialize)]
struct User {
id: i64,
username: String,
email: String,
}
impl User {
async fn find_one(id: i64) -> Result<Self, Error> {
let node = /* run a MATCH with driver, extract User node */;
let properties = node.properties();
Ok(Self {
id: node.node_identity(),
username: properties.get("username").unwrap().clone().try_into()?,
email: properties.get("email").unwrap().clone().try_into()?,
})
}
}
Something like that, anyway...
Maybe there's a compelling use case out there, though - I'm definitely willing to reconsider if that's the case.
Saw in #10 that full deserialization of
Value
to rust data types was yet to be implemented. I took an initial stab at it. I'd like to get someone more familiar with Serde to look at it, to make sure I'm on the right path. I borrowed quite a bit from theserde_json
crate (specifically their Value deserializer). Deserializing the special types (likeNode
orRelationship
) are the bits I'm not 100% sure about.Feedback welcome, before I finish up support for V2 types. Also curious if the deserialization would be accepted standalone, or if I need to do serialization in this PR too?
TODO: