3 unstable releases
0.2.0 | Oct 27, 2021 |
---|---|
0.1.1 | Oct 15, 2021 |
0.1.0 | Oct 14, 2021 |
#62 in #cassandra
Used in stargate-grpc
17KB
224 lines
Derive macros for stargate-grpc
This crate provides the following derive macros:
IntoValue
– enables converting a Rust struct to aValue
of a user-defined CQL type; use this when you want to bind a single UDT field in a queryTryFromValue
– enables converting aValue
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;
use this if you want to bind many fields of a single Rust struct in a single call tobind
TryFromRow
– enables converting aRow
received in a result set to a Rust value
Example
use 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.
Dependencies
~1.6–3MB
~60K SLoC