Macro diesel::Identifiable [] [src]

macro_rules! Identifiable {
    (
        $(())*
        #[table_name($table_name:ident)]
        $($rest:tt)*
    ) => { ... };
    (
        $args:tt
        #[$ignore:meta]
        $($rest:tt)*
    ) => { ... };
    (
        $args:tt
        $(pub)* struct $($body:tt)*
    ) => { ... };
    (
        (
            table_name = $table_name:ident,
            struct_ty = $struct_ty:ty,
        ),
        fields = [{
            field_name: id,
            column_name: $column_name:ident,
            field_ty: $field_ty:ty,
            field_kind: $field_kind:ident,
        } $($fields:tt)*],
    ) => { ... };
    (
        $args:tt,
        fields = [{
            field_name: $field_name:ident,
            column_name: $column_name:ident,
            field_ty: $field_ty:ty,
            field_kind: $field_kind:ident,
        } $($fields:tt)*],
    ) => { ... };
    (
        ($($args:tt)*)
        $struct_name:ident
        $body:tt $(;)*
    ) => { ... };
}

Implements the Identifiable trait for a given struct. This macro should be called by copy/pasting the definition of the struct into it.

The struct must have a field called id, and the type of that field must be Copy. This macro does not work with tuple structs.

Example

struct User {
    id: i32,
    name: String,
}

Identifiable! {
    #[table_name(users)]
    struct User {
        id: i32,
        name: String,
    }
}