Skip to main content

cast_derive/
lib.rs

1//! Cast derive macros. `#[derive(Model)]` generates the trait impl, columns
2//! accessor, FromRow impl, and inherent helpers. Attribute macros for relationships.
3
4mod model;
5mod relation;
6
7use proc_macro::TokenStream;
8
9#[proc_macro_derive(
10    Model,
11    attributes(table, primary_key, has_many, has_one, belongs_to, soft_deletes)
12)]
13pub fn derive_model(input: TokenStream) -> TokenStream {
14    let input = syn::parse_macro_input!(input as syn::DeriveInput);
15    match model::expand(&input) {
16        Ok(ts) => ts.into(),
17        Err(err) => err.to_compile_error().into(),
18    }
19}