Skip to main content

ferric_fred/
search_type.rs

1/// How `series/search` interprets the search text (the `search_type` request
2/// parameter).
3#[derive(Debug, Clone, Copy, PartialEq, Eq)]
4#[non_exhaustive]
5pub enum SearchType {
6    /// Match against series attributes and full text (`full_text`, FRED's
7    /// default).
8    FullText,
9    /// Match against the series ID (`series_id`).
10    SeriesId,
11}
12
13impl SearchType {
14    /// The FRED query code for this search type.
15    pub fn query_code(self) -> &'static str {
16        match self {
17            Self::FullText => "full_text",
18            Self::SeriesId => "series_id",
19        }
20    }
21}
22
23#[cfg(test)]
24mod tests {
25    use super::*;
26
27    #[test]
28    fn query_codes_match_fred() {
29        assert_eq!(SearchType::FullText.query_code(), "full_text");
30        assert_eq!(SearchType::SeriesId.query_code(), "series_id");
31    }
32}