qbase/
lib.rs

1//! # The QUIC base library
2//!
3//! The `qbase` library defines the necessary basic structures in the QUIC protocol,
4//! including connection IDs, stream IDs, frames, packets, keys, parameters, error codes, etc.
5//!
6//! Additionally, based on these basic structures,
7//! it defines components for various mechanisms in QUIC,
8//! including flow control, handshake, tokens, stream ID management, connection ID management, etc.
9//!
10//! Finally, the `qbase` module also defines some utility functions
11//! for handling common data structures in the QUIC protocol.
12//!
13
14use std::ops::{Index, IndexMut};
15
16/// Operations about QUIC connection IDs.
17pub mod cid;
18/// [QUIC errors](https://www.rfc-editor.org/rfc/rfc9000.html#name-error-codes).
19pub mod error;
20/// QUIC connection-level flow control.
21pub mod flow;
22/// QUIC frames and their codec.
23pub mod frame;
24/// Handshake signal for QUIC connections.
25pub mod handshake;
26/// Endpoint address and Pathway.
27pub mod net;
28/// QUIC packets and their codec.
29pub mod packet;
30/// [QUIC transport parameters and their codec](https://www.rfc-editor.org/rfc/rfc9000.html#name-transport-parameter-encodin).
31pub mod param;
32/// QUIC client and server roles.
33pub mod role;
34/// Stream id types and controllers for different roles and different directions.
35pub mod sid;
36/// Max idle timer and defer idle timer.
37pub mod time;
38/// Issuing, storing and verifing tokens operations.
39pub mod token;
40/// Utilities for common data structures.
41pub mod util;
42/// [Variable-length integers](https://www.rfc-editor.org/rfc/rfc9000.html#name-variable-length-integer-enc).
43pub mod varint;
44
45/// The epoch of sending, usually been seen as the index of spaces.
46#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Debug)]
47pub enum Epoch {
48    Initial = 0,
49    Handshake = 1,
50    Data = 2,
51}
52
53impl Epoch {
54    pub const EPOCHS: [Epoch; 3] = [Epoch::Initial, Epoch::Handshake, Epoch::Data];
55    /// An iterator for the epoch of each spaces.
56    ///
57    /// Equals to `Epoch::EPOCHES.iter()`
58    pub fn iter() -> std::slice::Iter<'static, Epoch> {
59        Self::EPOCHS.iter()
60    }
61
62    /// The number of epoches.
63    pub const fn count() -> usize {
64        Self::EPOCHS.len()
65    }
66}
67
68impl<T> Index<Epoch> for [T]
69where
70    T: Sized,
71{
72    type Output = T;
73
74    fn index(&self, index: Epoch) -> &Self::Output {
75        self.index(index as usize)
76    }
77}
78
79impl<T> IndexMut<Epoch> for [T]
80where
81    T: Sized,
82{
83    fn index_mut(&mut self, index: Epoch) -> &mut Self::Output {
84        self.index_mut(index as usize)
85    }
86}
87
88#[cfg(test)]
89mod tests {}