pub trait AsField<F: Field + Into<String>> { }
Expand description
Used to tie a type implementing Collection
to its companion Field
type.
§Example
Defining an enum
as a set of fields for use in a mongo query.
use mongod::{AsField, Field};
#[derive(Bson, Mongo)]
#[mongo(collection="users")]
pub struct User {
pub name: String,
}
impl AsField<UserField> for User {}
pub enum UserField {
Name,
}
impl Field for UserField {}
impl From<UserField> for String {
fn from(field: UserField) -> String {
match field {
UserField::Name => "name".to_owned(),
}
}
}