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