1
0
mirror of https://github.com/fafhrd91/actix-net synced 2025-06-28 23:30:36 +02:00

add io parameters

This commit is contained in:
Nikolay Kim
2019-03-11 12:01:55 -07:00
parent f696914038
commit 787255d030
9 changed files with 267 additions and 87 deletions

View File

@ -31,3 +31,67 @@ impl ServerConfig {
self.secure.as_ref().set(true)
}
}
#[derive(Copy, Clone, Debug)]
pub enum Protocol {
Unknown,
Http10,
Http11,
Http2,
Proto1,
Proto2,
Proto3,
Proto4,
Proto5,
Proto6,
}
pub struct Io<T, P = ()> {
io: T,
proto: Protocol,
params: P,
}
impl<T> Io<T, ()> {
pub fn new(io: T) -> Self {
Self {
io,
proto: Protocol::Unknown,
params: (),
}
}
}
impl<T, P> Io<T, P> {
pub fn from_parts(io: T, params: P, proto: Protocol) -> Self {
Self { io, params, proto }
}
pub fn into_parts(self) -> (T, P, Protocol) {
(self.io, self.params, self.proto)
}
pub fn io(&self) -> &T {
&self.io
}
pub fn io_mut(&mut self) -> &mut T {
&mut self.io
}
pub fn protocol(&self) -> Protocol {
self.proto
}
/// Maps an Io<_, P> to Io<_, U> by applying a function to a contained value.
pub fn map<U, F>(self, op: F) -> Io<T, U>
where
F: FnOnce(P) -> U,
{
Io {
io: self.io,
proto: self.proto,
params: op(self.params),
}
}
}