Coverage Report

Created: 2025-10-28 06:41

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/h2/src/frame/priority.rs
Line
Count
Source
1
use crate::frame::*;
2
3
#[derive(Debug, Eq, PartialEq)]
4
pub struct Priority {
5
    stream_id: StreamId,
6
    dependency: StreamDependency,
7
}
8
9
#[derive(Debug, Eq, PartialEq)]
10
pub struct StreamDependency {
11
    /// The ID of the stream dependency target
12
    dependency_id: StreamId,
13
14
    /// The weight for the stream. The value exposed (and set) here is always in
15
    /// the range [0, 255], instead of [1, 256] (as defined in section 5.3.2.)
16
    /// so that the value fits into a `u8`.
17
    weight: u8,
18
19
    /// True if the stream dependency is exclusive.
20
    is_exclusive: bool,
21
}
22
23
impl Priority {
24
236
    pub fn load(head: Head, payload: &[u8]) -> Result<Self, Error> {
25
236
        let dependency = StreamDependency::load(payload)?;
26
27
193
        if dependency.dependency_id() == head.stream_id() {
28
96
            return Err(Error::InvalidDependencyId);
29
97
        }
30
31
97
        Ok(Priority {
32
97
            stream_id: head.stream_id(),
33
97
            dependency,
34
97
        })
35
236
    }
36
}
37
38
impl<B> From<Priority> for Frame<B> {
39
97
    fn from(src: Priority) -> Self {
40
97
        Frame::Priority(src)
41
97
    }
<h2::frame::Frame as core::convert::From<h2::frame::priority::Priority>>::from
Line
Count
Source
39
97
    fn from(src: Priority) -> Self {
40
97
        Frame::Priority(src)
41
97
    }
Unexecuted instantiation: <h2::frame::Frame<h2::proto::streams::prioritize::Prioritized<bytes::bytes::Bytes>> as core::convert::From<h2::frame::priority::Priority>>::from
42
}
43
44
// ===== impl StreamDependency =====
45
46
impl StreamDependency {
47
4.63k
    pub fn new(dependency_id: StreamId, weight: u8, is_exclusive: bool) -> Self {
48
4.63k
        StreamDependency {
49
4.63k
            dependency_id,
50
4.63k
            weight,
51
4.63k
            is_exclusive,
52
4.63k
        }
53
4.63k
    }
54
55
4.67k
    pub fn load(src: &[u8]) -> Result<Self, Error> {
56
4.67k
        if src.len() != 5 {
57
43
            return Err(Error::InvalidPayloadLength);
58
4.63k
        }
59
60
        // Parse the stream ID and exclusive flag
61
4.63k
        let (dependency_id, is_exclusive) = StreamId::parse(&src[..4]);
62
63
        // Read the weight
64
4.63k
        let weight = src[4];
65
66
4.63k
        Ok(StreamDependency::new(dependency_id, weight, is_exclusive))
67
4.67k
    }
68
69
4.63k
    pub fn dependency_id(&self) -> StreamId {
70
4.63k
        self.dependency_id
71
4.63k
    }
72
}