Macro diesel::impl_Identifiable [] [src]

macro_rules! impl_Identifiable {
    (
        $(())*
        $(#[$option_name:ident $option_value:tt])*
        $(pub)* struct $($rest:tt)*
    ) => { ... };
    (
        (options = $options:tt, $($args:tt)*),
        found_option_with_name = table_name,
        value = ($table_name:ident),
    ) => { ... };
    (
        (
            options = $ignore:tt,
            table_name = $table_name:ident,
            body = $($body:tt)*
        ),
        found_option_with_name = primary_key,
        value = $primary_key_names:tt,
    ) => { ... };
    (
        (
            table_name = $table_name:ident,
            struct_ty = $struct_ty:ty,
            lifetimes = ($($lifetimes:tt),*),
        ),
        found_fields_with_field_names,
        fields = [$({
            field_name: $field_name:ident,
            column_name: $column_name:ident,
            field_ty: $field_ty:ty,
            field_kind: $field_kind:ident,
            $($rest:tt)*
        })*],
    ) => { ... };
    (
        (
            table_name = $table_name:ident,
            primary_key_names = $primary_key_names:tt,
            $($args:tt)*
        ),
        fields = $fields:tt,
    ) => { ... };
    (
        ($($args:tt)*)
        $struct_name:ident <$($lifetimes:tt),*>
        $body:tt $(;)*
    ) => { ... };
    (
        ($($args:tt)*)
        $struct_name:ident
        $body:tt $(;)*
    ) => { ... };
}

Implements the Identifiable trait for a reference to 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,
}

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