macro_rules! bind_newtype {
($name:ident($inner:ty)) => { ... };
}Expand description
Implement ToValue and FromValue for a single-field newtype by
delegating to the inner type — the “derivable for newtypes” story, without
a proc-macro crate.
use keelson_core::{FromValue, ToValue, Value};
#[derive(Debug, Clone, PartialEq)]
pub struct UserId(pub i64);
keelson_exec::bind_newtype!(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 tuple structs only: a multi-field type has no obvious single column shape, and refusing is the honest move — write the two impls by hand (about six lines) and put the domain rule where it belongs.