stargate-grpc-derive

Crates.iostargate-grpc-derive
lib.rsstargate-grpc-derive
version0.2.0
sourcesrc
created_at2021-10-14 17:40:56.369622
updated_at2021-10-27 08:28:01.785804
descriptionStruct mapper for stargate-grpc
homepagehttps://github.com/stargate/stargate-grpc-rust-client
repositoryhttps://github.com/stargate/stargate-grpc-rust-client
max_upload_size
id465030
size16,781
Piotr Kołaczkowski (pkolaczk)

documentation

README

Derive macros for 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 query
  • TryFromValue – 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 row
  • IntoValues – 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 to bind
  • TryFromRow – enables converting a Row 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.

Commit count: 85

cargo fmt