firestore_structured_query/
order.rs

1use googleapis_tonic_google_firestore_v1::google::firestore::v1::structured_query;
2
3use crate::FieldPath;
4
5/// A Firestore query order.
6///
7/// <https://firebase.google.com/docs/firestore/reference/rpc/google.firestore.v1#order>
8///
9/// ```rust
10/// # fn example_order() -> firestore_structured_query::Result<()> {
11/// use firestore_structured_query::{FieldPath, Order};
12/// use googleapis_tonic_google_firestore_v1::google::firestore::v1::structured_query;
13/// let order1: Order = FieldPath::raw("field1").ascending();
14/// let order2: Order = FieldPath::raw("field2").descending();
15/// assert_eq!(
16///     structured_query::Order::from(order1),
17///     structured_query::Order {
18///         field: Some(structured_query::FieldReference {
19///             field_path: "field1".to_string()
20///         }),
21///         direction: structured_query::Direction::Ascending as i32
22///     }
23/// );
24/// assert_eq!(
25///     structured_query::Order::from(order2),
26///     structured_query::Order {
27///         field: Some(structured_query::FieldReference {
28///             field_path: "field2".to_string()
29///         }),
30///         direction: structured_query::Direction::Descending as i32
31///     }
32/// );
33/// #     Ok(())
34/// # }
35/// ```
36#[derive(Clone, Debug, PartialEq)]
37pub struct Order(structured_query::Order);
38
39impl Order {
40    pub(crate) fn new(field_path: FieldPath, direction: structured_query::Direction) -> Self {
41        Self(structured_query::Order {
42            field: Some(structured_query::FieldReference::from(field_path)),
43            direction: direction as i32,
44        })
45    }
46}
47
48impl std::convert::From<Order> for structured_query::Order {
49    fn from(order: Order) -> Self {
50        order.0
51    }
52}