[−][src]Derive Macro mongod_derive::Mongo
#[derive(Mongo)]
{
// Attributes available to this derive:
#[mongo]
}Derives mongo traits on the decorated type.
Container Attributes
#[mongo(collection = "...")]: derives theCollectiontrait#[mongo(field)]: derives theAsField&Fieldtraits#[mongo(filter)]: derives theAsFilter&Filtertraits#[mongo(update)]: derives theAsUpdate&Updatetraits
#[mongo(collection = "...")]
Tells the derive to implement the Collection trait where the "..." is the name of the
collection.
#[derive(Mongo)] #[mongo(collection = "users")] pub struct User { name: String, age: u32, }
#[mongo(field)]
Tells the derive to implement the AsField & Field traits.
#[derive(Mongo)] #[mongo(field)] pub struct User { name: String, age: u32, } // The derived field enum can be exposed from the derived module which uses the type's name in // snake_case use self::user::Field;
#[mongo(filter)]
Tells the derive to implement the AsFilter & Filter traits.
#[derive(Mongo)] #[mongo(filter)] pub struct User { name: String, age: u32, } // The derived filter struct can be exposed from the derived module which uses the type's name in // snake_case use self::user::Filter;
#[mongo(update)]
Tells the derive to implement the AsUpdate & Update traits.
#[derive(Mongo)] #[mongo(update)] pub struct User { name: String, age: u32, } // The derived update struct can be exposed from the derived module which uses the type's name in // snake_case use self::user::Update;
Field Attributes
#[mongo(serde)]: tells the derive that the field should be handled using serde#[mongo(skip)]: tells the derive to skip the field forfield,filter&update
#[mongo(serde)]
Tells the derive that the field should be handled using serde
#[derive(Mongo)] #[mongo(collection = "users")] pub struct User { name: String, #[mongo(serde)] age: u32, }
#[mongo(skip)]
Tells the derive to skip the field for field, filter & update
#[derive(Mongo)] #[mongo(collection = "users")] pub struct User { name: String, #[mongo(skip)] age: u32, }