stargate-grpc
This crate provides the following derive macros:
IntoValue
– enables converting a Rust struct to a Value
of a user-defined CQL type;
use this when you want to bind a single UDT field in a queryTryFromValue
– enables converting a Value
representing a user-defined CQL type to a Rust struct;
use this to read a single UDT column value from a rowIntoValues
– enables converting a Rust struct to many arguments of a query at once; bind
TryFromRow
– enables converting a Row
received in a result set to a Rust value```rust,skt-simple-main use stargategrpc::Value; use stargategrpc_derive::{IntoValue, TryFromValue};
struct User { id: i64, login: String }
let user = User { id: 1, login: "user".to_string() };
// Convert User to Value: let value = Value::from(user); assert_eq!(value, Value::udt(vec![("id", Value::bigint(1)), ("login", Value::string("user"))]));
// Now convert it back to User: let user: User = value.tryinto().unwrap(); asserteq!(user.id, 1); asserteq!(user.login, "user".tostring());
```
See crate documentation for more examples.