1
2
Fork 0
mirror of https://github.com/mat-1/azalea.git synced 2025-08-02 06:16:04 +00:00

Military-grade server implementation (#40)

* Military-grade server implementation

* Add doc comments
This commit is contained in:
Honbra 2022-11-14 20:25:59 +01:00 committed by GitHub
parent 6eee543a33
commit 9f78b3f4a7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -302,7 +302,8 @@ where
R1: ProtocolPacket + Debug,
W1: ProtocolPacket + Debug,
{
fn from<R2, W2>(connection: Connection<R1, W1>) -> Connection<R2, W2>
/// Creates a `Connection` of a type from a `Connection` of another type. Useful for servers or custom packets.
pub fn from<R2, W2>(connection: Connection<R1, W1>) -> Connection<R2, W2>
where
R2: ProtocolPacket + Debug,
W2: ProtocolPacket + Debug,
@ -323,4 +324,25 @@ where
},
}
}
/// Convert an existing `TcpStream` into a `Connection`. Useful for servers.
pub fn wrap(stream: TcpStream) -> Connection<R1, W1> {
let (read_stream, write_stream) = stream.into_split();
Connection {
reader: ReadConnection {
read_stream,
buffer: BytesMut::new(),
compression_threshold: None,
dec_cipher: None,
_reading: PhantomData,
},
writer: WriteConnection {
write_stream,
compression_threshold: None,
enc_cipher: None,
_writing: PhantomData,
},
}
}
}