Coverage Report

Created: 2026-09-01 06:49

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
206
    pub fn load(head: Head, payload: &[u8]) -> Result<Self, Error> {
25
206
        let dependency = StreamDependency::load(payload)?;
26
27
168
        if dependency.dependency_id() == head.stream_id() {
28
67
            return Err(Error::InvalidDependencyId);
29
101
        }
30
31
101
        Ok(Priority {
32
101
            stream_id: head.stream_id(),
33
101
            dependency,
34
101
        })
35
206
    }
36
}
37
38
impl<B> From<Priority> for Frame<B> {
39
101
    fn from(src: Priority) -> Self {
40
101
        Frame::Priority(src)
41
101
    }
<h2::frame::Frame as core::convert::From<h2::frame::priority::Priority>>::from
Line
Count
Source
39
101
    fn from(src: Priority) -> Self {
40
101
        Frame::Priority(src)
41
101
    }
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
3.88k
    pub fn new(dependency_id: StreamId, weight: u8, is_exclusive: bool) -> Self {
48
3.88k
        StreamDependency {
49
3.88k
            dependency_id,
50
3.88k
            weight,
51
3.88k
            is_exclusive,
52
3.88k
        }
53
3.88k
    }
54
55
3.92k
    pub fn load(src: &[u8]) -> Result<Self, Error> {
56
3.92k
        if src.len() != 5 {
57
38
            return Err(Error::InvalidPayloadLength);
58
3.88k
        }
59
60
        // Parse the stream ID and exclusive flag
61
3.88k
        let (dependency_id, is_exclusive) = StreamId::parse(&src[..4]);
62
63
        // Read the weight
64
3.88k
        let weight = src[4];
65
66
3.88k
        Ok(StreamDependency::new(dependency_id, weight, is_exclusive))
67
3.92k
    }
68
69
3.88k
    pub fn dependency_id(&self) -> StreamId {
70
3.88k
        self.dependency_id
71
3.88k
    }
72
}