• 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

55.0
/rust/cbork-utils/src/decode_context.rs
1
//! CBOR decode context which could used as an argument for the `minicbor::Decode` logic
2

3
/// a type alias for the deterministic error handler function
4
pub type DeterministicErrorHandler =
5
    Box<dyn FnMut(minicbor::decode::Error) -> Result<(), minicbor::decode::Error>>;
6

7
/// CBOR `minicbor::Decode` context struct.
8
pub enum DecodeCtx {
9
    /// Decode a CBOR object applying deterministic decoding rules (RFC 8949
10
    /// Section 4.2).
11
    Deterministic,
12
    /// Decode a CBOR object **NOT** applying deterministic decoding rules (RFC 8949
13
    /// Section 4.2).
14
    ///
15
    /// Optionally it could carry an deterministic decoding error handler, so if provided
16
    /// deterministic decoding rule is applied and the error message passed to the
17
    /// handler function
18
    NonDeterministic(Option<DeterministicErrorHandler>),
19
}
20

21
impl DecodeCtx {
22
    /// Returns `DecodeCtx::NonDeterministic` variant
23
    /// Decode a CBOR object **NOT** applying deterministic decoding rules (RFC 8949
24
    /// Section 4.2).
25
    #[must_use]
26
    pub fn non_deterministic() -> Self {
5✔
27
        Self::NonDeterministic(None)
5✔
28
    }
5✔
29

30
    /// Returns `DecodeCtx::NonDeterministic` variant
31
    /// Decode a CBOR object **NOT** applying deterministic decoding rules (RFC 8949
32
    /// Section 4.2).
33
    ///
34
    /// When deterministic decoding rule is applied, the error message passed to
35
    /// the provided `handler`
36
    #[must_use]
37
    pub fn non_deterministic_with_handler(
×
NEW
38
        handler: impl FnMut(minicbor::decode::Error) -> Result<(), minicbor::decode::Error> + 'static
×
39
    ) -> Self {
×
40
        Self::NonDeterministic(Some(Box::new(handler)))
×
41
    }
×
42

43
    /// Depends on the set `DecodeCtx` variant applies the provided deterministic
44
    /// validation
45
    pub(crate) fn try_check(
53✔
46
        &mut self,
53✔
47
        f: impl FnOnce() -> Result<(), minicbor::decode::Error>,
53✔
48
    ) -> Result<(), minicbor::decode::Error> {
53✔
49
        match self {
12✔
50
            Self::Deterministic => f(),
41✔
51
            Self::NonDeterministic(None) => Ok(()),
12✔
52
            Self::NonDeterministic(Some(h)) => {
×
53
                if let Err(err) = f() {
×
54
                    h(err)
×
55
                } else {
56
                    Ok(())
×
57
                }
58
            },
59
        }
60
    }
53✔
61
}
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