mongod/
field.rs

1/// Used to mark an `enum` as a viable type for use in sorting.
2///
3/// # Example
4///
5/// Defining an `enum` as a set of fields for use in a mongo query.
6///
7/// ```
8/// # mod wrapper {
9/// # use mongod_derive::{Bson, Mongo};
10/// use mongod::Field;
11///
12/// #[derive(Bson, Mongo)]
13/// #[mongo(collection="users")]
14/// pub struct User {
15///     pub name: String,
16/// }
17///
18/// pub enum UserField {
19///     Name,
20/// }
21///
22/// impl Field for UserField {}
23///
24/// impl From<UserField> for String {
25///     fn from(field: UserField) -> String {
26///         match field {
27///             UserField::Name => "name".to_owned(),
28///         }
29///     }
30/// }
31/// # }
32/// ```
33pub trait Field {}
34
35/// Used to tie a type implementing [`Collection`](./trait.Collection.html) to its companion `Field` type.
36///
37/// # Example
38///
39/// Defining an `enum` as a set of fields for use in a mongo query.
40///
41/// ```
42/// # mod wrapper {
43/// # use mongod_derive::{Bson, Mongo};
44/// use mongod::{AsField, Field};
45///
46/// #[derive(Bson, Mongo)]
47/// #[mongo(collection="users")]
48/// pub struct User {
49///     pub name: String,
50/// }
51///
52/// impl AsField<UserField> for User {}
53///
54/// pub enum UserField {
55///     Name,
56/// }
57///
58/// impl Field for UserField {}
59///
60/// impl From<UserField> for String {
61///     fn from(field: UserField) -> String {
62///         match field {
63///             UserField::Name => "name".to_owned(),
64///         }
65///     }
66/// }
67/// # }
68/// ```
69pub trait AsField<F: Field + Into<String>> {}