Debian Codegraph @

third_party/rust/neqo-http3/src/push_id.rs

raw
1 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
2 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
3 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
4 // option. This file may not be copied, modified, or distributed
5 // except according to those terms.
6
7 use std::{
8 fmt::{self, Display, Formatter},
9 ops::{Add, Sub},
10 };
11
12 #[derive(Clone, Copy, Debug, Eq, PartialEq, PartialOrd)]
13 pub struct PushId(u64);
14
15 impl PushId {
16 #[must_use]
17 pub const fn new(id: u64) -> Self {
18 Self(id)
19 }
20
21 pub fn next(&mut self) {
22 self.0 += 1;
23 }
24 }
25
26 impl From<u64> for PushId {
27 fn from(id: u64) -> Self {
28 Self(id)
29 }
30 }
31
32 impl From<PushId> for u64 {
33 fn from(id: PushId) -> Self {
34 id.0
35 }
36 }
37
38 impl Display for PushId {
39 fn fmt(&self, f: &mut Formatter) -> fmt::Result {
40 write!(f, "{}", self.0)
41 }
42 }
43
44 impl Sub for PushId {
45 type Output = Self;
46
47 fn sub(self, rhs: Self) -> Self {
48 Self(self.0 - rhs.0)
49 }
50 }
51
52 impl Add<u64> for PushId {
53 type Output = Self;
54
55 fn add(self, rhs: u64) -> Self {
56 Self(self.0 + rhs)
57 }
58 }