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

input-output-hk / catalyst-libs / 19767538642

28 Nov 2025 03:07PM UTC coverage: 67.749% (-0.02%) from 67.771%
19767538642

push

github

web-flow
feat(rust): Implement `dht_provide()` and `dht_get_providers()` (#666)

* Implement `dht_provide()` and `dht_get_providers()`

* Cleanup

* Fix lints

* `identity()` returns identity, not peer id

0 of 24 new or added lines in 1 file covered. (0.0%)

11 existing lines in 3 files now uncovered.

13961 of 20607 relevant lines covered (67.75%)

2635.4 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 applying deterministic decoding rules (RFC 8949
13
    /// Section 4.2).
14
    /// Additional apply `RFC 8949 Section 4.2.3` for array entries, so it become
15
    /// deterministically sorted.
16
    ArrayDeterministic,
17
    /// Decode a CBOR object **NOT** applying deterministic decoding rules (RFC 8949
18
    /// Section 4.2).
19
    ///
20
    /// Optionally it could carry an deterministic decoding error handler, so if provided
21
    /// deterministic decoding rule is applied and the error message passed to the
22
    /// handler function
23
    NonDeterministic(Option<DeterministicErrorHandler>),
24
}
25

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

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

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