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

pulibrary / bibdata / c41dd2ab-dc4c-4404-9348-696a969af050

18 Aug 2025 01:20PM UTC coverage: 92.477% (-0.08%) from 92.556%
c41dd2ab-dc4c-4404-9348-696a969af050

push

circleci

christinach
Support format id structure
as a string and as an object

related to: https://github.com/pulibrary/bibdata/issues/2828#issuecomment-3192808622

38 of 41 new or added lines in 2 files covered. (92.68%)

6 existing lines in 1 file now uncovered.

7019 of 7590 relevant lines covered (92.48%)

425.22 hits per line

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

58.49
/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
// When we provide a format facet to Ruby, it must be provided as a String.
31
// Implementing Display allows us to map FormatFacet values to Strings so
32
// that Ruby can access them.
33
impl Display for FormatFacet {
34
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
×
35
        match self {
×
36
            Self::ArchivalItem => write!(f, "Archival item"),
×
37
            Self::DataFile => write!(f, "Data file"),
×
38
            Self::MusicalScore => write!(f, "Musical score"),
×
39
            Self::SeniorThesis => write!(f, "Senior thesis"),
×
40
            Self::VideoProjectedMedium => write!(f, "Video/Projected medium"),
×
41
            Self::VisualMaterial => write!(f, "Visual material"),
×
42
            _ => write!(f, "{:?}", self),
×
43
        }
44
    }
×
45
}
46

47
#[derive(Debug)]
48
pub struct NoFormatMatches;
49

50
impl FromStr for FormatFacet {
51
    type Err = NoFormatMatches;
52

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

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

81
#[cfg(test)]
82
mod tests {
83
    use super::*;
84

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

113
    #[test]
114
    fn it_can_be_created_from_str() {
1✔
115
        assert_eq!(FormatFacet::from_str("Books").unwrap(), FormatFacet::Book);
1✔
116
        assert_eq!(
1✔
117
            FormatFacet::from_str("Reports").unwrap(),
1✔
118
            FormatFacet::Report
119
        );
120
        assert_eq!(
1✔
121
            FormatFacet::from_str("Serials").unwrap(),
1✔
122
            FormatFacet::Journal
123
        );
124
        assert_eq!(
1✔
125
            FormatFacet::from_str("Pamphlets").unwrap(),
1✔
126
            FormatFacet::Book
127
        );
128
    }
1✔
129
}
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