Repository: diesel-rs/diesel
File: diesel_derives/src/lib.rs (Rust)

Code before:
/// By default, any `Option` fields on the struct are skipped if their value is
/// `None`. If you would like to assign `NULL` to the field instead, you can
/// annotate your struct with `#[diesel(treat_none_as_null = true)]`.
///
/// # Attributes
///
/// ## Optional container attributes
///
/// * `#[diesel(treat_none_as_null = true)]`, specifies that
///    the derive should threat `None` values as `NULL`. By default
///    `Option::<T>::None` is just skipped. To insert a `NULL` using default
///    behavior use `Option::<Option<T>>::Some(None)`
/// * `#[diesel(table_name = path::to::table)]`, specifies a path to the table for which the
///    current type is a changeset. The path is relative to the current module.
///    If this attribute is not used, the type name converted to
///    `snake_case` with an added `s` is used as table name.
/// * `#[diesel(primary_key(id1, id2))]` to specify the struct field that
///    that corresponds to the primary key. If not used, `id` will be
///    assumed as primary key field
///
/// ## Optional field attributes
///
/// * `#[diesel(column_name = some_column_name)]`, overrides the column name
///    of the current field to `some_column_name`. By default the field
///    name is used as column name.
/// * `#[diesel(serialize_as = "SomeType")]`, instead of serializing the actual
///    field type, Diesel will convert the field into `SomeType` using `.into` and
///    serialize that instead. By default this derive will serialize directly using
///    the actual field type.
#[proc_macro_error]
#[proc_macro_derive(
    AsChangeset,
    attributes(diesel, table_name, column_name, primary_key, changeset_options)
)]
pub fn derive_as_changeset(input: TokenStream) -> TokenStream {
    as_changeset::derive(parse_macro_input!(input)).into()
}

/// Implements all required variants of `AsExpression`
///
/// This derive will generate the following impls:
///
/// - `impl AsExpression<SqlType> for YourType`
/// - `impl AsExpression<Nullable<SqlType>> for YourType`
/// - `impl AsExpression<SqlType> for &'a YourType`
/// - `impl AsExpression<Nullable<SqlType>> for &'a YourType`
/// - `impl AsExpression<SqlType> for &'a &'b YourType`
/// - `impl AsExpression<Nullable<SqlType>> for &'a &'b YourType`
///
/// If your type is unsized,
/// you can specify this by adding the annotation `#[diesel(not_sized)]`

Review comment (suggestion):
```suggestion
/// * `#[diesel(serialize_as = SomeType)]`, instead of serializing the actual
```

Code after:
/// By default, any `Option` fields on the struct are skipped if their value is
/// `None`. If you would like to assign `NULL` to the field instead, you can
/// annotate your struct with `#[diesel(treat_none_as_null = true)]`.
///
/// # Attributes
///
/// ## Optional container attributes
///
/// * `#[diesel(treat_none_as_null = true)]`, specifies that
///    the derive should threat `None` values as `NULL`. By default
///    `Option::<T>::None` is just skipped. To insert a `NULL` using default
///    behavior use `Option::<Option<T>>::Some(None)`
/// * `#[diesel(table_name = path::to::table)]`, specifies a path to the table for which the
///    current type is a changeset. The path is relative to the current module.
///    If this attribute is not used, the type name converted to
///    `snake_case` with an added `s` is used as table name.
/// * `#[diesel(primary_key(id1, id2))]` to specify the struct field that
///    that corresponds to the primary key. If not used, `id` will be
///    assumed as primary key field
///
/// ## Optional field attributes
///
/// * `#[diesel(column_name = some_column_name)]`, overrides the column name
///    of the current field to `some_column_name`. By default the field
///    name is used as column name.
/// * `#[diesel(serialize_as = SomeType)]`, instead of serializing the actual
///    field type, Diesel will convert the field into `SomeType` using `.into` and
///    serialize that instead. By default this derive will serialize directly using
///    the actual field type.
#[proc_macro_error]
#[proc_macro_derive(
    AsChangeset,
    attributes(diesel, table_name, column_name, primary_key, changeset_options)
)]
pub fn derive_as_changeset(input: TokenStream) -> TokenStream {
    as_changeset::derive(parse_macro_input!(input)).into()
}

/// Implements all required variants of `AsExpression`
///
/// This derive will generate the following impls:
///
/// - `impl AsExpression<SqlType> for YourType`
/// - `impl AsExpression<Nullable<SqlType>> for YourType`
/// - `impl AsExpression<SqlType> for &'a YourType`
/// - `impl AsExpression<Nullable<SqlType>> for &'a YourType`
/// - `impl AsExpression<SqlType> for &'a &'b YourType`
/// - `impl AsExpression<Nullable<SqlType>> for &'a &'b YourType`
///
/// If your type is unsized,
/// you can specify this by adding the annotation `#[diesel(not_sized)]`