#[derive(Bind)]
{
// Attributes available to this derive:
#[keelson]
}
Expand description
The derive macros, re-exported behind the macros feature.
Bind writes the ToValue/FromValue pair for a
newtype — the bound a keelson-gen column override must satisfy.
FromRow maps a result row onto a struct; the trait it
implements lives in keelson-exec, which any user of it already depends on.
Both are documented in the keelson-macros crate.
keelson_core::Bind is the derive, keelson_exec::Bind the trait: two
namespaces, so importing both is fine.
Implement keelson_core::ToValue and keelson_core::FromValue for a
newtype by delegating to its single field — the pair
keelson_exec::Bind requires, and so the pair a keelson-gen column
override must satisfy.
use keelson_core::{Bind, FromValue as _, ToValue as _, Value};
#[derive(Debug, PartialEq, Bind)]
struct UserId(i64);
const _: () = keelson_exec::assert_bind::<UserId>();
assert_eq!(UserId(7).to_value(), Value::I64(7));
assert_eq!(UserId::from_value(Value::I64(7)).unwrap(), UserId(7));Single-field structs only — tuple or named, generic or not. Multi-field structs, enums, unions and unit structs are compile errors naming the restriction; see the crate documentation for the reasoning.