• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

pulibrary / bibdata / 880759a6-1cd8-4c26-ac18-7fa2f37cee33

14 Aug 2025 04:24PM UTC coverage: 92.642% (+0.02%) from 92.625%
880759a6-1cd8-4c26-ac18-7fa2f37cee33

Pull #2849

circleci

sandbergja
Rename module for clarity

Co-authored-by: Christina Chortaria <christinach@users.noreply.github.com>
Pull Request #2849: Refactor format facet code to Rust

325 of 361 new or added lines in 8 files covered. (90.03%)

5 existing lines in 1 file now uncovered.

6988 of 7543 relevant lines covered (92.64%)

429.18 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

69.81
/lib/bibdata_rs/src/solr/format_facet.rs
1
use serde::{Deserialize, Deserializer, Serialize};
2
use std::{fmt::Display, str::FromStr};
3

4
#[allow(dead_code)]
5
#[derive(Copy, Clone, Debug, Serialize, PartialEq)]
6
pub enum FormatFacet {
7
    #[serde(rename = "Archival item")]
8
    ArchivalItem,
9
    Audio,
10
    Book,
11
    Coin,
12
    #[serde(rename = "Data file")]
13
    DataFile,
14
    Databases,
15
    Journal,
16
    Manuscript,
17
    Map,
18
    Microform,
19
    #[serde(rename = "Musical score")]
20
    MusicalScore,
21
    Report,
22
    #[serde(rename = "Senior thesis")]
23
    SeniorThesis,
24
    #[serde(rename = "Video/Projected medium")]
25
    VideoProjectedMedium,
26
    #[serde(rename = "Visual material")]
27
    VisualMaterial,
28
}
29

30
impl Display for FormatFacet {
NEW
31
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
×
NEW
32
        match self {
×
NEW
33
            Self::ArchivalItem => write!(f, "Archival item"),
×
NEW
34
            Self::DataFile => write!(f, "Data file"),
×
NEW
35
            Self::MusicalScore => write!(f, "Musical score"),
×
NEW
36
            Self::SeniorThesis => write!(f, "Senior thesis"),
×
NEW
37
            Self::VideoProjectedMedium => write!(f, "Video/Projected medium"),
×
NEW
38
            Self::VisualMaterial => write!(f, "Visual material"),
×
NEW
39
            _ => write!(f, "{:?}", self),
×
40
        }
NEW
41
    }
×
42
}
43

44
#[derive(Debug)]
45
pub struct NoFormatMatches;
46

47
impl FromStr for FormatFacet {
48
    type Err = NoFormatMatches;
49

50
    fn from_str(s: &str) -> Result<Self, Self::Err> {
45✔
51
        match s {
45✔
52
            "Book" => Ok(Self::Book),
45✔
53
            "Books" => Ok(Self::Book),
45✔
54
            "Pamphlets" => Ok(Self::Book),
5✔
55
            "Reports" => Ok(Self::Report),
3✔
56
            "Serials" => Ok(Self::Journal),
2✔
UNCOV
57
            "Senior thesis" => Ok(Self::SeniorThesis),
×
UNCOV
58
            _ => Err(NoFormatMatches),
×
59
        }
60
    }
45✔
61
}
62

63
impl<'de> Deserialize<'de> for FormatFacet {
64
    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
40✔
65
    where
40✔
66
        D: Deserializer<'de>,
40✔
67
    {
68
        let s = String::deserialize(deserializer)?;
40✔
69
        FromStr::from_str(&s).map_err(|_err| {
40✔
UNCOV
70
            serde::de::Error::invalid_value(
×
UNCOV
71
                serde::de::Unexpected::Str(&s),
×
UNCOV
72
                &"a valid catalog format",
×
73
            )
74
        })
×
75
    }
40✔
76
}
77

78
#[cfg(test)]
79
mod tests {
80
    use super::*;
81

82
    #[test]
83
    fn it_serializes() {
1✔
84
        assert_eq!(
1✔
85
            serde_json::to_string(&FormatFacet::ArchivalItem).unwrap(),
1✔
86
            r#""Archival item""#
87
        );
88
        assert_eq!(
1✔
89
            serde_json::to_string(&FormatFacet::DataFile).unwrap(),
1✔
90
            r#""Data file""#
91
        );
92
        assert_eq!(
1✔
93
            serde_json::to_string(&FormatFacet::MusicalScore).unwrap(),
1✔
94
            r#""Musical score""#
95
        );
96
        assert_eq!(
1✔
97
            serde_json::to_string(&FormatFacet::SeniorThesis).unwrap(),
1✔
98
            r#""Senior thesis""#
99
        );
100
        assert_eq!(
1✔
101
            serde_json::to_string(&FormatFacet::VideoProjectedMedium).unwrap(),
1✔
102
            r#""Video/Projected medium""#
103
        );
104
        assert_eq!(
1✔
105
            serde_json::to_string(&FormatFacet::VisualMaterial).unwrap(),
1✔
106
            r#""Visual material""#
107
        );
108
    }
1✔
109

110
    #[test]
111
    fn it_can_be_created_from_str() {
1✔
112
        assert_eq!(FormatFacet::from_str("Books").unwrap(), FormatFacet::Book);
1✔
113
        assert_eq!(
1✔
114
            FormatFacet::from_str("Reports").unwrap(),
1✔
115
            FormatFacet::Report
116
        );
117
        assert_eq!(
1✔
118
            FormatFacet::from_str("Serials").unwrap(),
1✔
119
            FormatFacet::Journal
120
        );
121
        assert_eq!(
1✔
122
            FormatFacet::from_str("Pamphlets").unwrap(),
1✔
123
            FormatFacet::Book
124
        );
125
    }
1✔
126
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc