aerospike / aerospike-client-rust

Rust client for the Aerospike database
https://www.aerospike.com/
Other
82 stars 26 forks source link

Implement serde::Serialize and serde::Deserialize for aerospike::Value and aerospike::Record #123

Open austinjones opened 2 years ago

austinjones commented 2 years ago

Hello, Aerospike is a great database! Master-master replication is very cool. But we are struggling to write Rust code that interfaces it.

We are getting stuck on serialization and deserialization code. The aerospike::Value and aerospike::Record structs do not implement serde::ser::Serialize and serde::de::Deserialize. Any conversions between Rust structs and Aerospike values need to be implemented manually, field by field. Deserializing is particularly tricky, because aerospike::Value may be any variant. Application code needs to match on the enum in order to extract each value, and manually handle deserialization errors (invalid variants).

This library should be able to serialize this rust struct into an aerospike::Record:

use serde::{Serialize, Deserialize};
#[derive(Serialize, Deserialize)]
struct MyModel {
  amount: f64,
  description: String,
  inner: AnotherStruct
}

It should also be able to deserialize an aerospike::Record into the struct, with errors if fields have incompatible Value variants.

jonas32 commented 2 years ago

Hey, the client has serde serializers at least. Its behind a feature flag.