Skip to main content

s2n_quic_dc/stream/socket/
application.rs

1// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2// SPDX-License-Identifier: Apache-2.0
3
4use super::{Protocol, Socket, TransportFeatures};
5use std::sync::Arc;
6
7pub mod builder;
8
9pub use builder::Builder;
10
11pub trait Application: 'static + Send + Sync {
12    fn protocol(&self) -> Protocol;
13
14    fn features(&self) -> TransportFeatures;
15
16    fn write_application(&self) -> &dyn Socket;
17
18    fn read_application(&self) -> &dyn Socket;
19}
20
21impl<T: ?Sized + Application> Application for Arc<T> {
22    #[inline]
23    fn protocol(&self) -> Protocol {
24        (**self).protocol()
25    }
26
27    #[inline]
28    fn features(&self) -> TransportFeatures {
29        (**self).features()
30    }
31
32    #[inline]
33    fn write_application(&self) -> &dyn Socket {
34        (**self).write_application()
35    }
36
37    #[inline]
38    fn read_application(&self) -> &dyn Socket {
39        (**self).read_application()
40    }
41}
42
43pub struct Single<S>(pub(crate) S);
44
45impl<S: Socket> Application for Single<S> {
46    #[inline]
47    fn protocol(&self) -> Protocol {
48        self.0.protocol()
49    }
50
51    #[inline]
52    fn features(&self) -> TransportFeatures {
53        self.0.features()
54    }
55
56    #[inline]
57    fn write_application(&self) -> &dyn Socket {
58        &self.0
59    }
60
61    #[inline]
62    fn read_application(&self) -> &dyn Socket {
63        &self.0
64    }
65}
66
67pub struct Pair<S: Socket> {
68    read: S,
69    write: S,
70}
71
72impl<S: Socket> Application for Pair<S> {
73    #[inline]
74    fn protocol(&self) -> Protocol {
75        self.read.protocol()
76    }
77
78    #[inline]
79    fn features(&self) -> TransportFeatures {
80        self.read.features()
81    }
82
83    #[inline]
84    fn write_application(&self) -> &dyn Socket {
85        &self.write
86    }
87
88    #[inline]
89    fn read_application(&self) -> &dyn Socket {
90        &self.read
91    }
92}