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

butlergroup / rust-libp2p / 18610913338

18 Oct 2025 04:41AM UTC coverage: 78.379% (+2.5%) from 75.842%
18610913338

push

github

butlergroup
	modified:   .github/workflows/ci.yml

36944 of 47135 relevant lines covered (78.38%)

37728.24 hits per line

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

100.0
/swarm/src/connection/supported_protocols.rs
1
use std::collections::HashSet;
2

3
use crate::{handler::ProtocolsChange, StreamProtocol};
4

5
#[derive(Default, Clone, Debug)]
6
pub struct SupportedProtocols {
7
    protocols: HashSet<StreamProtocol>,
8
}
9

10
impl SupportedProtocols {
11
    pub fn on_protocols_change(&mut self, change: ProtocolsChange) -> bool {
261✔
12
        match change {
261✔
13
            ProtocolsChange::Added(added) => {
259✔
14
                let mut changed = false;
259✔
15

16
                for p in added {
868✔
17
                    changed |= self.protocols.insert(p.clone());
609✔
18
                }
609✔
19

20
                changed
259✔
21
            }
22
            ProtocolsChange::Removed(removed) => {
2✔
23
                let mut changed = false;
2✔
24

25
                for p in removed {
4✔
26
                    changed |= self.protocols.remove(p);
2✔
27
                }
2✔
28

29
                changed
2✔
30
            }
31
        }
32
    }
261✔
33

34
    pub fn iter(&self) -> impl Iterator<Item = &StreamProtocol> {
270✔
35
        self.protocols.iter()
270✔
36
    }
270✔
37
}
38

39
#[cfg(test)]
40
mod tests {
41
    use super::*;
42
    use crate::handler::{ProtocolsAdded, ProtocolsRemoved};
43

44
    #[test]
45
    fn protocols_change_added_returns_correct_changed_value() {
1✔
46
        let mut protocols = SupportedProtocols::default();
1✔
47

48
        let changed = protocols.on_protocols_change(add_foo());
1✔
49
        assert!(changed);
1✔
50

51
        let changed = protocols.on_protocols_change(add_foo());
1✔
52
        assert!(!changed);
1✔
53

54
        let changed = protocols.on_protocols_change(add_foo_bar());
1✔
55
        assert!(changed);
1✔
56
    }
1✔
57

58
    #[test]
59
    fn protocols_change_removed_returns_correct_changed_value() {
1✔
60
        let mut protocols = SupportedProtocols::default();
1✔
61

62
        let changed = protocols.on_protocols_change(remove_foo());
1✔
63
        assert!(!changed);
1✔
64

65
        protocols.on_protocols_change(add_foo());
1✔
66

67
        let changed = protocols.on_protocols_change(remove_foo());
1✔
68
        assert!(changed);
1✔
69
    }
1✔
70

71
    fn add_foo() -> ProtocolsChange<'static> {
3✔
72
        ProtocolsChange::Added(ProtocolsAdded {
3✔
73
            protocols: FOO_PROTOCOLS.iter(),
3✔
74
        })
3✔
75
    }
3✔
76

77
    fn add_foo_bar() -> ProtocolsChange<'static> {
1✔
78
        ProtocolsChange::Added(ProtocolsAdded {
1✔
79
            protocols: FOO_BAR_PROTOCOLS.iter(),
1✔
80
        })
1✔
81
    }
1✔
82

83
    fn remove_foo() -> ProtocolsChange<'static> {
2✔
84
        ProtocolsChange::Removed(ProtocolsRemoved {
2✔
85
            protocols: FOO_PROTOCOLS.iter(),
2✔
86
        })
2✔
87
    }
2✔
88

89
    static FOO_PROTOCOLS: &[StreamProtocol] = &[StreamProtocol::new("/foo")];
90
    static FOO_BAR_PROTOCOLS: &[StreamProtocol] =
91
        &[StreamProtocol::new("/foo"), StreamProtocol::new("/bar")];
92
}
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