Crate wither [] [src]

An ODM for MongoDB built upon the mongo rust driver.

This project makes use of associated constants as of 0.2.0, so you will need to be running rust >= 1.20.

An example of how you might use this library to define a model for a MongoDB collection.

#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct User {
    /// The user's unique ID.
    #[serde(rename = "_id", skip_serializing_if = "Option::is_none")]
    pub id: Option<bson::oid::ObjectId>,

    /// The user's unique email.
    pub email: String,
}

impl<'a> wither::Model<'a> for User {

    const COLLECTION_NAME: &'static str = "users";

    fn id(&self) -> Option<bson::oid::ObjectId> {
        return self.id.clone();
    }

    fn set_id(&mut self, oid: bson::oid::ObjectId) {
        self.id = Some(oid);
    }

    fn indexes() -> Vec<IndexModel> {
        return vec![
            IndexModel{
                keys: doc!{"email" => 1},
                options: wither::basic_index_options("unique-email", true, Some(true), None, None),
            },
        ];
    }
}

Reexports

pub use model::Model;
pub use model::basic_index_options;

Modules

model

Model is the central type in this crate. The entire purpose of this create is to simplify the process of interfacing with MongoDB in Rust for patterns which should be simple.

Structs

FindOptions

Options for collection queries.

Type Definitions

Document

Alias for OrderedDocument.