• 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

98.63
/lib/bibdata_rs/src/marc/fixed_field/leader.rs
1
use marctk::Record;
2

3
pub enum TypeOfRecord {
4
    LanguageMaterial,
5
    NotatedMusic,
6
    ManuscriptNotatedMusic,
7
    CartographicMaterial,
8
    ManuscriptCartographicMaterial,
9
    ProjectedMedium,
10
    NonmusicalSoundRecording,
11
    MusicalSoundRecording,
12
    TwoDimensionalNonProjectableGraphic,
13
    ComputerFile,
14
    Kit,
15
    MixedMaterials,
16
    ThreeDimensionalArtifactOrNaturallyOcurringObject,
17
    ManuscriptLanguageMaterial,
18
}
19

20
impl TryFrom<char> for TypeOfRecord {
21
    type Error = String;
22

23
    fn try_from(value: char) -> Result<Self, Self::Error> {
336✔
24
        match value {
336✔
25
            'a' => Ok(Self::LanguageMaterial),
93✔
26
            'c' => Ok(Self::NotatedMusic),
11✔
27
            'd' => Ok(Self::ManuscriptNotatedMusic),
34✔
28
            'e' => Ok(Self::CartographicMaterial),
11✔
29
            'f' => Ok(Self::ManuscriptCartographicMaterial),
11✔
30
            'g' => Ok(Self::ProjectedMedium),
11✔
31
            'i' => Ok(Self::NonmusicalSoundRecording),
11✔
32
            'j' => Ok(Self::MusicalSoundRecording),
11✔
33
            'k' => Ok(Self::TwoDimensionalNonProjectableGraphic),
11✔
34
            'm' => Ok(Self::ComputerFile),
11✔
35
            'o' => Ok(Self::Kit),
11✔
36
            'p' => Ok(Self::MixedMaterials),
11✔
37
            'r' => Ok(Self::ThreeDimensionalArtifactOrNaturallyOcurringObject),
11✔
38
            't' => Ok(Self::ManuscriptLanguageMaterial),
66✔
39
            _ => Err(format!("{} is not a valid type of record", value)),
22✔
40
        }
41
    }
336✔
42
}
43

44
impl TryFrom<&Record> for TypeOfRecord {
45
    type Error = String;
46
    fn try_from(value: &Record) -> Result<Self, Self::Error> {
336✔
47
        value
336✔
48
            .leader()
336✔
49
            .chars()
336✔
50
            .nth(6)
336✔
51
            .ok_or("No Type of Record at LDR/06")?
336✔
52
            .try_into()
336✔
53
    }
336✔
54
}
55

56
pub enum BibliographicLevel {
57
    MonographicComponentPart,
58
    SerialComponentPart,
59
    Collection,
60
    Subunit,
61
    IntegratingResource,
62
    MonographItem,
63
    Serial,
64
}
65

66
impl BibliographicLevel {
67
    pub fn is_serial(&self) -> bool {
7✔
68
        matches!(self, Self::SerialComponentPart | Self::Serial)
7✔
69
    }
7✔
70

71
    pub fn is_monograph(&self) -> bool {
8✔
72
        matches!(
3✔
73
            self,
8✔
74
            Self::MonographicComponentPart
75
                | Self::SerialComponentPart
76
                | Self::Collection
77
                | Self::Subunit
78
                | Self::MonographItem
79
        )
80
    }
8✔
81
}
82

83
impl TryFrom<char> for BibliographicLevel {
84
    type Error = String;
85

86
    fn try_from(value: char) -> Result<Self, Self::Error> {
105✔
87
        match value {
105✔
88
            'a' => Ok(Self::MonographicComponentPart),
4✔
89
            'b' => Ok(Self::SerialComponentPart),
4✔
90
            'c' => Ok(Self::Collection),
4✔
91
            'd' => Ok(Self::Subunit),
4✔
92
            'i' => Ok(Self::IntegratingResource),
4✔
93
            'm' => Ok(Self::MonographItem),
28✔
94
            's' => Ok(Self::Serial),
9✔
95
            _ => Err(format!("{} is not a valid bibliographic level", value)),
48✔
96
        }
97
    }
105✔
98
}
99

100
impl TryFrom<&Record> for BibliographicLevel {
101
    type Error = String;
102
    fn try_from(value: &Record) -> Result<Self, Self::Error> {
105✔
103
        value
105✔
104
            .leader()
105✔
105
            .chars()
105✔
106
            .nth(7)
105✔
107
            .ok_or("No Bibliographic level at LDR/07")?
105✔
108
            .try_into()
105✔
109
    }
105✔
110
}
111

112
pub fn is_monograph(record: &Record) -> bool {
8✔
113
    match BibliographicLevel::try_from(record) {
8✔
114
        Ok(level) => level.is_monograph(),
8✔
NEW
115
        _ => false,
×
116
    }
117
}
8✔
118

119
#[cfg(test)]
120
mod tests {
121
    use super::*;
122

123
    #[test]
124
    fn it_can_identify_a_serials_record() {
1✔
125
        let serial_record = Record::from_breaker("=LDR 01644cas a2200397 a 4500").unwrap();
1✔
126
        assert!(BibliographicLevel::try_from(&serial_record)
1✔
127
            .unwrap()
1✔
128
            .is_serial());
1✔
129

130
        let monograph_record = Record::from_breaker("=LDR 04137cam a2200853Ii 4500").unwrap();
1✔
131
        assert!(!BibliographicLevel::try_from(&monograph_record)
1✔
132
            .unwrap()
1✔
133
            .is_serial());
1✔
134
    }
1✔
135

136
    #[test]
137
    fn it_can_identify_manuscript_notated_music() {
1✔
138
        let manuscript_notated_music =
1✔
139
            Record::from_breaker("=LDR 02190cdm a2200385 i 4500").unwrap();
1✔
140
        assert!(matches!(
1✔
141
            TypeOfRecord::try_from(&manuscript_notated_music),
1✔
142
            Ok(TypeOfRecord::ManuscriptNotatedMusic)
143
        ));
144
    }
1✔
145
}
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