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

kaidokert / picojson-rs / 15977103664

30 Jun 2025 03:26PM UTC coverage: 94.482% (+0.5%) from 94.027%
15977103664

Pull #16

github

kaidokert
Rename things
Pull Request #16: Rename things

13 of 13 new or added lines in 3 files covered. (100.0%)

25 existing lines in 3 files now uncovered.

2089 of 2211 relevant lines covered (94.48%)

134.33 hits per line

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

88.0
/picojson/src/json_string.rs
1
// SPDX-License-Identifier: Apache-2.0
2

3
use core::ops::Deref;
4

5
/// Represents a JSON string.
6
/// 'a is the lifetime of the original input buffer.
7
/// 'b is the lifetime of the scratch buffer.
8
#[derive(Debug, PartialEq, Eq)]
9
pub enum String<'a, 'b> {
10
    /// A raw slice from the original input, used when no un-escaping is needed.
11
    Borrowed(&'a str),
12
    /// A slice from the scratch buffer, used when a string had to be un-escaped.
13
    Unescaped(&'b str),
14
}
15

16
impl String<'_, '_> {
17
    /// Returns the string as a `&str`, whether borrowed or unescaped.
18
    pub fn as_str(&self) -> &str {
16✔
19
        match self {
16✔
20
            String::Borrowed(s) => s,
10✔
21
            String::Unescaped(s) => s,
6✔
22
        }
23
    }
16✔
24
}
25

26
impl AsRef<str> for String<'_, '_> {
27
    fn as_ref(&self) -> &str {
5✔
28
        self.as_str()
5✔
29
    }
5✔
30
}
31

32
impl Deref for String<'_, '_> {
33
    type Target = str;
34

35
    fn deref(&self) -> &Self::Target {
36✔
36
        match self {
36✔
37
            String::Borrowed(s) => s,
32✔
38
            String::Unescaped(s) => s,
4✔
39
        }
40
    }
36✔
41
}
42

43
impl core::fmt::Display for String<'_, '_> {
UNCOV
44
    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
×
45
        f.write_str(self.as_str())
×
46
    }
×
47
}
48

49
#[cfg(test)]
50
mod tests {
51
    use super::*;
52

53
    #[test]
54
    fn test_json_string_deref() {
1✔
55
        let borrowed = String::Borrowed("test");
1✔
56
        assert_eq!(&*borrowed, "test");
1✔
57
        assert_eq!(borrowed.len(), 4);
1✔
58

59
        // Test that it works as a string reference
60
        fn takes_str(s: &str) -> usize {
1✔
61
            s.len()
1✔
62
        }
1✔
63
        assert_eq!(takes_str(&borrowed), 4);
1✔
64
    }
1✔
65
}
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

© 2026 Coveralls, Inc