Coverage Report

Created: 2025-09-05 06:17

/rust/registry/src/index.crates.io-6f17d22bba15001f/http-1.3.1/src/version.rs
Line
Count
Source (jump to first uncovered line)
1
//! HTTP version
2
//!
3
//! This module contains a definition of the `Version` type. The `Version`
4
//! type is intended to be accessed through the root of the crate
5
//! (`http::Version`) rather than this module.
6
//!
7
//! The `Version` type contains constants that represent the various versions
8
//! of the HTTP protocol.
9
//!
10
//! # Examples
11
//!
12
//! ```
13
//! use http::Version;
14
//!
15
//! let http11 = Version::HTTP_11;
16
//! let http2 = Version::HTTP_2;
17
//! assert!(http11 != http2);
18
//!
19
//! println!("{:?}", http2);
20
//! ```
21
22
use std::fmt;
23
24
/// Represents a version of the HTTP spec.
25
#[derive(PartialEq, PartialOrd, Copy, Clone, Eq, Ord, Hash)]
26
pub struct Version(Http);
27
28
impl Version {
29
    /// `HTTP/0.9`
30
    pub const HTTP_09: Version = Version(Http::Http09);
31
32
    /// `HTTP/1.0`
33
    pub const HTTP_10: Version = Version(Http::Http10);
34
35
    /// `HTTP/1.1`
36
    pub const HTTP_11: Version = Version(Http::Http11);
37
38
    /// `HTTP/2.0`
39
    pub const HTTP_2: Version = Version(Http::H2);
40
41
    /// `HTTP/3.0`
42
    pub const HTTP_3: Version = Version(Http::H3);
43
}
44
45
#[derive(PartialEq, PartialOrd, Copy, Clone, Eq, Ord, Hash)]
46
enum Http {
47
    Http09,
48
    Http10,
49
    Http11,
50
    H2,
51
    H3,
52
    __NonExhaustive,
53
}
54
55
impl Default for Version {
56
    #[inline]
57
0
    fn default() -> Version {
58
0
        Version::HTTP_11
59
0
    }
60
}
61
62
impl fmt::Debug for Version {
63
0
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
64
        use self::Http::*;
65
66
0
        f.write_str(match self.0 {
67
0
            Http09 => "HTTP/0.9",
68
0
            Http10 => "HTTP/1.0",
69
0
            Http11 => "HTTP/1.1",
70
0
            H2 => "HTTP/2.0",
71
0
            H3 => "HTTP/3.0",
72
0
            __NonExhaustive => unreachable!(),
73
        })
74
0
    }
75
}