Crates.io | stargate-grpc-derive |
lib.rs | stargate-grpc-derive |
version | 0.2.0 |
source | src |
created_at | 2021-10-14 17:40:56.369622 |
updated_at | 2021-10-27 08:28:01.785804 |
description | Struct mapper for stargate-grpc |
homepage | https://github.com/stargate/stargate-grpc-rust-client |
repository | https://github.com/stargate/stargate-grpc-rust-client |
max_upload_size | |
id | 465030 |
size | 16,781 |
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 valueuse stargate_grpc::Value;
use stargate_grpc_derive::{IntoValue, TryFromValue};
#[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.try_into().unwrap();
assert_eq!(user.id, 1);
assert_eq!(user.login, "user".to_string());
See crate documentation for more examples.