Coverage Report

Created: 2026-02-11 07:08

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/h2/src/ext.rs
Line
Count
Source
1
//! Extensions specific to the HTTP/2 protocol.
2
3
use crate::hpack::BytesStr;
4
5
use bytes::Bytes;
6
use std::fmt;
7
8
/// Represents the `:protocol` pseudo-header used by
9
/// the [Extended CONNECT Protocol].
10
///
11
/// [Extended CONNECT Protocol]: https://datatracker.ietf.org/doc/html/rfc8441#section-4
12
#[derive(Clone, Eq, PartialEq)]
13
pub struct Protocol {
14
    value: BytesStr,
15
}
16
17
impl Protocol {
18
    /// Converts a static string to a protocol name.
19
0
    pub const fn from_static(value: &'static str) -> Self {
20
0
        Self {
21
0
            value: BytesStr::from_static(value),
22
0
        }
23
0
    }
24
25
    /// Returns a str representation of the header.
26
3.20k
    pub fn as_str(&self) -> &str {
27
3.20k
        self.value.as_str()
28
3.20k
    }
29
30
1.44k
    pub(crate) fn try_from(bytes: Bytes) -> Result<Self, std::str::Utf8Error> {
31
        Ok(Self {
32
1.44k
            value: BytesStr::try_from(bytes)?,
33
        })
34
1.44k
    }
35
}
36
37
impl<'a> From<&'a str> for Protocol {
38
0
    fn from(value: &'a str) -> Self {
39
0
        Self {
40
0
            value: BytesStr::from(value),
41
0
        }
42
0
    }
43
}
44
45
impl AsRef<[u8]> for Protocol {
46
0
    fn as_ref(&self) -> &[u8] {
47
0
        self.value.as_ref()
48
0
    }
49
}
50
51
impl fmt::Debug for Protocol {
52
0
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
53
0
        self.value.fmt(f)
54
0
    }
55
}