Derive Macro spark_orm_derive::TModel

source ·
#[derive(TModel)]
{
    // Attributes available to this derive:
    #[model]
    #[coll_name]
}
Expand description

Procedural macro to derive the Model trait for a struct.

This macro processes the input struct marked with the #[_model] attribute and generates an implementation of the Model trait. The trait includes a constructor method and an index registration method. The constructor initializes the struct and registers its indexes in a MongoDB collection. The #[_model] attribute is used to annotate the struct that should be treated as a model.

§Example

#[derive(Model)]
struct Book {
    #[model(unique)]
    title: String,
    #[model(index)]
    subject: &'static str,
    author: Option<String>
}

§Attributes

  • #[model]: Annotates the struct to indicate that it should be treated as a model.

§Returns

A TokenStream representing the expanded code with the generated implementation of the Model trait for the input struct.