Skip to main content

ferric_fred/
sort_order.rs

1/// Sort order for returned observations, by observation date (the `sort_order`
2/// request parameter).
3#[derive(Debug, Clone, Copy, PartialEq, Eq)]
4#[non_exhaustive]
5pub enum SortOrder {
6    /// Oldest first (`asc`, FRED's default).
7    Ascending,
8    /// Newest first (`desc`).
9    Descending,
10}
11
12impl SortOrder {
13    /// The FRED query code for this sort order.
14    pub fn query_code(self) -> &'static str {
15        match self {
16            Self::Ascending => "asc",
17            Self::Descending => "desc",
18        }
19    }
20}
21
22#[cfg(test)]
23mod tests {
24    use super::*;
25
26    #[test]
27    fn query_codes_match_fred() {
28        assert_eq!(SortOrder::Ascending.query_code(), "asc");
29        assert_eq!(SortOrder::Descending.query_code(), "desc");
30    }
31}