wtx 0.28.0

A collection of different transport implementations and related tools focused primarily on web technologies.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
/// Implements a bunch of auxiliary methods for enums.
#[macro_export]
macro_rules! create_enum {
  (
    $(#[$container_mac:meta])*
    $v:vis enum $enum_ident:ident<$n:ty> {
      $(
        $(#[$variant_mac_fixed:meta])*
        $variant_ident_fixed:ident = ($variant_n_fixed:literal $(, $variant_str_fixed:literal)? $(| $variant_str_fixed_n:literal)*)
      ),* $(,)?
    }
  ) => {
    $(#[$container_mac])*
    $v enum $enum_ident {
      $($(#[$variant_mac_fixed])* $variant_ident_fixed,)*
    }

    #[allow(dead_code, reason = "outside may or may not use methods")]
    impl $enum_ident {
      #[inline]
      /// An array that contains all variants
      $v fn all() -> [Self; { Self::len() }] {
        [$( $enum_ident::$variant_ident_fixed, )*]
      }

      #[inline]
      /// The total number of variants
      $v const fn len() -> usize {
        const { 0 $( + { let _: $n = $variant_n_fixed; 1 })* }
      }

      /// See [`$crate::misc::EnumVarStrings`].
      #[inline]
      $v const fn strings(&self) -> $crate::misc::EnumVarStrings<{
        #[allow(unused_mut, reason = "macro stuff")]
        let mut n;
        $({
          #[allow(unused_mut, reason = "repetition can be empty")]
          let mut local_n = 0;
          let _: $n = $variant_n_fixed;
          $({ let _ = $variant_str_fixed; local_n += 1; })?
          $({ let _ = $variant_str_fixed_n; local_n += 1; })*
          #[allow(unused_assignments, reason = "repetition can be empty")]
          { n = local_n; }
        })*
        n
      }> {
        match self {
          $(
            $enum_ident::$variant_ident_fixed => $crate::misc::EnumVarStrings {
              custom: [$($variant_str_fixed,)? $($variant_str_fixed_n,)*],
              ident: stringify!($variant_ident_fixed),
              number: stringify!($variant_n_fixed),
            },
          )*
        }
      }
    }

    #[allow(
      unused_qualifications,
      reason = "macro shouldn't control what the outside uses"
    )]
    impl core::fmt::Display for $enum_ident {
      #[inline]
      fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
        write!(f, "{}", self.strings().ident)
      }
    }

    impl From<$enum_ident> for $n {
      #[inline]
      fn from(from: $enum_ident) -> Self {
        match from {
          $($enum_ident::$variant_ident_fixed => $variant_n_fixed,)*
        }
      }
    }

    impl core::str::FromStr for $enum_ident {
      type Err = $crate::Error;

      #[inline]
      fn from_str(s: &str) -> Result<Self, Self::Err> {
        s.try_into()
      }
   }

    impl TryFrom<$n> for $enum_ident {
      type Error = $crate::Error;

      #[inline]
      fn try_from(from: $n) -> $crate::Result<Self> {
        let rslt = match from {
          $($variant_n_fixed => Self::$variant_ident_fixed,)*
          _ => return Err($crate::Error::UnexpectedUint { received: from.into() }),
        };
        Ok(rslt)
      }
    }

    impl TryFrom<&str> for $enum_ident {
      type Error = $crate::Error;

      #[inline]
      fn try_from(from: &str) -> $crate::Result<Self> {
        from.as_bytes().try_into()
      }
    }

    impl TryFrom<&[u8]> for $enum_ident {
      type Error = $crate::Error;

      #[inline]
      fn try_from(from: &[u8]) -> $crate::Result<Self> {
        match from {
          $(
            from if from == stringify!($variant_ident_fixed).as_bytes()
              || from == stringify!($variant_n_fixed).as_bytes()
              $(|| from == $variant_str_fixed.as_bytes())?
              $(|| from == $variant_str_fixed_n.as_bytes())* =>
            {
              Ok(Self::$variant_ident_fixed)
            },
          )*
          _ => Err($crate::Error::UnexpectedBytes {
            length: from.len().try_into().unwrap_or(u16::MAX),
            ty: core::any::type_name::<Self>().split("::").last().and_then(|el| el.get(..8)).unwrap_or_default().try_into()?,
          }),
        }
      }
    }
  }
}

/// Creates a vector containing the arguments.
#[macro_export]
macro_rules! vector {
  ($($tt:tt)*) => {
    $crate::misc::Vector::from_vec(alloc::vec![$($tt)*])
  };
}

macro_rules! _conn_params_methods {
  () => {
    /// The initial amount of "credit" a counterpart can have for sending data.
    #[inline]
    #[must_use]
    pub fn initial_window_len(mut self, elem: u32) -> Self {
      self.cp._initial_window_len = elem;
      self
    }

    /// The maximum number of data bytes or the sum of all frames that composed the body data.
    #[inline]
    #[must_use]
    pub fn max_body_len(mut self, elem: u32) -> Self {
      self.cp._max_body_len = elem;
      self
    }

    /// Maximum number of active concurrent streams
    #[inline]
    #[must_use]
    pub fn max_concurrent_streams_num(mut self, elem: u32) -> Self {
      self.cp._max_concurrent_streams_num = elem;
      self
    }

    /// Maximum frame ***payload*** length
    #[inline]
    #[must_use]
    pub fn max_frame_len(mut self, elem: u32) -> Self {
      self.cp._max_frame_len = elem;
      self
    }

    /// Maximum HPACK length
    ///
    /// Indicates the maximum length of the HPACK structure that holds cached decoded headers
    /// received from a counterpart.
    ///
    /// - The first parameter indicates the local HPACK ***decoder*** length that is externally
    ///   advertised and can become the remote HPACK ***encoder*** length.
    /// - The second parameter indicates the maximum local HPACK ***encoder*** length. In other words,
    ///   it doesn't allow external actors to dictate very large lengths.
    #[inline]
    #[must_use]
    pub fn max_hpack_len(mut self, elem: (u32, u32)) -> Self {
      self.cp._max_hpack_len = elem;
      self
    }

    /// The maximum number of bytes of the entire set of headers in a request/response.
    #[inline]
    #[must_use]
    pub fn max_headers_len(mut self, elem: u32) -> Self {
      self.cp._max_headers_len = elem;
      self
    }

    /// Maximum number of receiving streams
    ///
    /// Servers only. Prevents clients from opening more than the specified number of streams.
    #[inline]
    #[must_use]
    pub fn max_recv_streams_num(mut self, elem: u32) -> Self {
      self.cp._max_recv_streams_num = elem;
      self
    }
  };
}

macro_rules! _debug {
  ($($tt:tt)+) => {
    #[cfg(feature = "tracing")]
    tracing::debug!($($tt)+);
  };
}

macro_rules! doc_bad_format {
  () => {
    "Couldn't create a new instance using `Arguments`."
  };
}

macro_rules! doc_many_elems_cap_overflow {
  () => {
    "There is no capacity left to insert a set of new elements."
  };
}

macro_rules! doc_out_of_bounds_params {
  () => {
    "Received parameters lead to outcomes that can't accurately represent the underlying data."
  };
}

macro_rules! doc_reserve_overflow {
  () => {
    "It was not possible to reserve more memory"
  };
}

macro_rules! doc_single_elem_cap_overflow {
  () => {
    "There is no capacity left to insert a new element."
  };
}

macro_rules! _internal_buffer_doc {
  () => {
    "Buffer used for internal operations."
  };
}

macro_rules! _internal_doc {
  () => {
    "Internal element not meant for public usage."
  };
}

macro_rules! _iter4 {
  ($slice:expr, $init:block, |$elem:ident| $block:block) => {{
    let mut iter = crate::misc::ArrayChunks::new($slice);
    for [a, b, c, d] in iter.by_ref() {
      $init
      let $elem = a;
      $block
      let $elem = b;
      $block
      let $elem = c;
      $block
      let $elem = d;
      $block
    }
    for elem in iter.into_remainder() {
      let $elem = elem;
      $block
    }
  }};
}

macro_rules! _iter4_mut {
  ($slice:expr, $init:block, |$elem:ident| $block:block) => {{
    let mut iter = crate::misc::ArrayChunksMut::new($slice);
    for [a, b, c, d] in iter.by_ref() {
      $init
      let $elem = a;
      $block
      let $elem = b;
      $block
      let $elem = c;
      $block
      let $elem = d;
      $block
    }
    for elem in iter.into_remainder() {
      let $elem = elem;
      $block
    }
  }};
}

macro_rules! _max_continuation_frames {
  () => {
    16
  };
}

macro_rules! _max_frames_mismatches {
  () => {
    32
  };
}

macro_rules! _simd {
  (
    fallback => $fallback:expr,
    16 => $_16:expr,
    32 => $_32:expr,
    64 => $_64:expr $(,)?
  ) => {{
    #[cfg(not(any(
      target_feature = "avx2",
      target_feature = "avx512f",
      target_feature = "neon",
      target_feature = "sse2"
    )))]
    let rslt = $fallback;

    #[cfg(all(
      target_feature = "neon",
      not(any(target_feature = "avx2", target_feature = "avx512f"))
    ))]
    let rslt = $_16;

    #[cfg(all(
      target_feature = "sse2",
      not(any(target_feature = "avx2", target_feature = "avx512f", target_feature = "neon"))
    ))]
    let rslt = $_16;

    #[cfg(all(target_feature = "avx2", not(target_feature = "avx512f")))]
    let rslt = $_32;

    #[cfg(target_feature = "avx512f")]
    let rslt = $_64;

    rslt
  }};
}

macro_rules! _simd_bytes {
  (
    ($align:ident, $bytes:expr),
    |$bytes_ident:ident| $bytes_expr:expr,
    |$before_align_ident:ident| $before_align_expr:expr,
    |$_16_ident:ident| $_16_expr:expr,
    |$_32_ident:ident| $_32_expr:expr,
    |$_64_ident:ident| $_64_expr:expr,
    |$after_align_ident:ident| $after_align_expr:expr $(,)?
  ) => {{
    // SAFETY: Changing a sequence of `u8` should be fine
    let (_prefix, _chunks, _suffix) = unsafe { $bytes.$align() };
    _simd! {
      fallback => {
        let _: [u8] = *_chunks;
        let _: [u8] = *$bytes;
        let $bytes_ident = $bytes; $bytes_expr;
      },
      16 => {
        let _: [[u8; 16]] = *_chunks;
        let $bytes_ident = _prefix; $bytes_expr
        let $before_align_ident = $bytes_ident; $before_align_expr;
        let $_16_ident = _chunks; $_16_expr;
        let $after_align_ident = _suffix; $after_align_expr;
        let $bytes_ident = $after_align_ident; $bytes_expr
      },
      32 => {
        let _: [[u8; 32]] = *_chunks;
        let $bytes_ident = _prefix; $bytes_expr
        let $before_align_ident = $bytes_ident; $before_align_expr;
        let $_32_ident = _chunks; $_32_expr;
        let $after_align_ident = _suffix; $after_align_expr;
        let $bytes_ident = $after_align_ident; $bytes_expr
      },
      64 => {
        let _: [[u8; 64]] = *_chunks;
        let $bytes_ident = _prefix; $bytes_expr
        let $before_align_ident = $bytes_ident; $before_align_expr;
        let $_64_ident = _chunks; $_64_expr;
        let $after_align_ident = _suffix; $after_align_expr;
        let $bytes_ident = $after_align_ident; $bytes_expr
      },
    }
  }};
}

macro_rules! _trace {
  ($($tt:tt)+) => {
    #[cfg(feature = "tracing")]
    tracing::trace!($($tt)+)
  };
}

macro_rules! _trace_span {
  ($($tt:tt)+) => {
    crate::misc::facades::span::_Span::_new(
      #[cfg(feature = "tracing")]
      tracing::trace_span!($($tt)+),
      #[cfg(not(feature = "tracing"))]
      ()
    )
  };
}