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/// QUIC packets and their codec.
27pub mod packet;
28/// [QUIC transport parameters and their codec](https://www.rfc-editor.org/rfc/rfc9000.html#name-transport-parameter-encodin).
29pub mod param;
30/// Stream id types and controllers for different roles and different directions.
31pub mod sid;
32/// Issuing, storing and verifing tokens operations.
33pub mod token;
34/// Utilities for common data structures.
35pub mod util;
36/// [Variable-length integers](https://www.rfc-editor.org/rfc/rfc9000.html#name-variable-length-integer-enc).
37pub mod varint;
38
39/// The epoch of sending, usually been seen as the index of spaces.
40#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Debug)]
41pub enum Epoch {
42 Initial = 0,
43 Handshake = 1,
44 Data = 2,
45}
46
47impl Epoch {
48 pub const EPOCHS: [Epoch; 3] = [Epoch::Initial, Epoch::Handshake, Epoch::Data];
49 /// An iterator for the epoch of each spaces.
50 ///
51 /// Equals to `Epoch::EPOCHES.iter()`
52 pub fn iter() -> std::slice::Iter<'static, Epoch> {
53 Self::EPOCHS.iter()
54 }
55
56 /// The number of epoches.
57 pub const fn count() -> usize {
58 Self::EPOCHS.len()
59 }
60}
61
62impl<T> Index<Epoch> for [T]
63where
64 T: Sized,
65{
66 type Output = T;
67
68 fn index(&self, index: Epoch) -> &Self::Output {
69 self.index(index as usize)
70 }
71}
72
73impl<T> IndexMut<Epoch> for [T]
74where
75 T: Sized,
76{
77 fn index_mut(&mut self, index: Epoch) -> &mut Self::Output {
78 self.index_mut(index as usize)
79 }
80}
81
82#[cfg(test)]
83mod tests {}