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

input-output-hk / catalyst-libs / 16758889759

05 Aug 2025 07:03PM UTC coverage: 65.822% (-0.2%) from 66.061%
16758889759

push

github

web-flow
feat(general): new rustfmt rules (#461)

* bump rust-ci

* update rustfmt.toml

* apply fmt

1488 of 2319 new or added lines in 158 files covered. (64.17%)

23 existing lines in 14 files now uncovered.

12150 of 18459 relevant lines covered (65.82%)

3171.34 hits per line

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

84.48
/rust/signed_doc/src/metadata/content_encoding.rs
1
//! Document Payload Content Encoding.
2

3
use std::{
4
    fmt::{Display, Formatter},
5
    str::FromStr,
6
};
7

8
/// IANA `CoAP` Content Encoding.
9
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
10
pub enum ContentEncoding {
11
    /// Brotli compression.format.
12
    Brotli,
13
}
14

15
impl ContentEncoding {
16
    /// Compress a Brotli payload
17
    ///
18
    /// # Errors
19
    /// Returns compression failure
20
    pub fn encode(
31✔
21
        self,
31✔
22
        mut payload: &[u8],
31✔
23
    ) -> anyhow::Result<Vec<u8>> {
31✔
24
        match self {
31✔
25
            Self::Brotli => {
26
                let brotli_params = brotli::enc::BrotliEncoderParams::default();
31✔
27
                let mut buf = Vec::new();
31✔
28
                brotli::BrotliCompress(&mut payload, &mut buf, &brotli_params)?;
31✔
29
                Ok(buf)
31✔
30
            },
31
        }
32
    }
31✔
33

34
    /// Decompress a Brotli payload
35
    ///
36
    /// # Errors
37
    ///  Returns decompression failure
38
    pub fn decode(
49✔
39
        self,
49✔
40
        mut payload: &[u8],
49✔
41
    ) -> anyhow::Result<Vec<u8>> {
49✔
42
        match self {
49✔
43
            Self::Brotli => {
44
                let mut buf = Vec::new();
49✔
45
                brotli::BrotliDecompress(&mut payload, &mut buf)?;
49✔
46
                Ok(buf)
48✔
47
            },
48
        }
49
    }
49✔
50
}
51

52
impl Display for ContentEncoding {
53
    fn fmt(
65✔
54
        &self,
65✔
55
        f: &mut Formatter<'_>,
65✔
56
    ) -> Result<(), std::fmt::Error> {
65✔
57
        match self {
65✔
58
            Self::Brotli => write!(f, "br"),
65✔
59
        }
60
    }
65✔
61
}
62

63
impl FromStr for ContentEncoding {
64
    type Err = anyhow::Error;
65

66
    fn from_str(encoding: &str) -> Result<Self, Self::Err> {
65✔
67
        match encoding {
65✔
68
            "br" => Ok(ContentEncoding::Brotli),
65✔
69
            _ => anyhow::bail!("Unsupported Content Encoding: {encoding:?}"),
×
70
        }
71
    }
65✔
72
}
73

74
impl<'de> serde::Deserialize<'de> for ContentEncoding {
75
    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
30✔
76
    where D: serde::Deserializer<'de> {
30✔
77
        let s = String::deserialize(deserializer)?;
30✔
78
        FromStr::from_str(&s).map_err(serde::de::Error::custom)
30✔
79
    }
30✔
80
}
81

82
impl serde::Serialize for ContentEncoding {
NEW
83
    fn serialize<S>(
×
NEW
84
        &self,
×
NEW
85
        serializer: S,
×
NEW
86
    ) -> Result<S::Ok, S::Error>
×
NEW
87
    where
×
NEW
88
        S: serde::Serializer,
×
89
    {
90
        self.to_string().serialize(serializer)
×
91
    }
×
92
}
93

94
impl minicbor::Encode<()> for ContentEncoding {
95
    fn encode<W: minicbor::encode::Write>(
34✔
96
        &self,
34✔
97
        e: &mut minicbor::Encoder<W>,
34✔
98
        _ctx: &mut (),
34✔
99
    ) -> Result<(), minicbor::encode::Error<W::Error>> {
34✔
100
        e.str(self.to_string().as_str())?;
34✔
101
        Ok(())
34✔
102
    }
34✔
103
}
104

105
impl minicbor::Decode<'_, ()> for ContentEncoding {
106
    fn decode(
36✔
107
        d: &mut minicbor::Decoder<'_>,
36✔
108
        _ctx: &mut (),
36✔
109
    ) -> Result<Self, minicbor::decode::Error> {
36✔
110
        d.str()?.parse().map_err(minicbor::decode::Error::message)
36✔
111
    }
36✔
112
}
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