aboutsummaryrefslogtreecommitdiff
path: root/azalea-protocol/src
diff options
context:
space:
mode:
authormat <github@matdoes.dev>2022-07-29 17:17:14 -0500
committermat <github@matdoes.dev>2022-07-29 17:17:14 -0500
commit1eef0a537e13b56d55a5a96e61a7e1361dbb02d6 (patch)
tree580624da689cfcdaa808252215f2f8d7a933b574 /azalea-protocol/src
parent637e0e09840ac3c4c3b6695ab940c0906215b49a (diff)
downloadazalea-drasl-1eef0a537e13b56d55a5a96e61a7e1361dbb02d6.tar.xz
simplify switching packet states
Diffstat (limited to 'azalea-protocol/src')
-rwxr-xr-xazalea-protocol/src/connect.rs42
1 files changed, 22 insertions, 20 deletions
diff --git a/azalea-protocol/src/connect.rs b/azalea-protocol/src/connect.rs
index cf251576..75c64517 100755
--- a/azalea-protocol/src/connect.rs
+++ b/azalea-protocol/src/connect.rs
@@ -74,25 +74,11 @@ impl Connection<ClientboundHandshakePacket, ServerboundHandshakePacket> {
}
pub fn login(self) -> Connection<ClientboundLoginPacket, ServerboundLoginPacket> {
- Connection {
- stream: self.stream,
- compression_threshold: self.compression_threshold,
- enc_cipher: self.enc_cipher,
- dec_cipher: self.dec_cipher,
- _reading: PhantomData,
- _writing: PhantomData,
- }
+ Connection::from(self)
}
pub fn status(self) -> Connection<ClientboundStatusPacket, ServerboundStatusPacket> {
- Connection {
- stream: self.stream,
- compression_threshold: self.compression_threshold,
- enc_cipher: self.enc_cipher,
- dec_cipher: self.dec_cipher,
- _reading: PhantomData,
- _writing: PhantomData,
- }
+ Connection::from(self)
}
}
@@ -118,11 +104,27 @@ impl Connection<ClientboundLoginPacket, ServerboundLoginPacket> {
}
pub fn game(self) -> Connection<ClientboundGamePacket, ServerboundGamePacket> {
+ Connection::from(self)
+ }
+}
+
+// rust doesn't let us implement From because allegedly it conflicts with
+// `core`'s "impl<T> From<T> for T" so we do this instead
+impl<R1, W1> Connection<R1, W1>
+where
+ R1: ProtocolPacket + Debug,
+ W1: ProtocolPacket + Debug,
+{
+ fn from<R2, W2>(connection: Connection<R1, W1>) -> Connection<R2, W2>
+ where
+ R2: ProtocolPacket + Debug,
+ W2: ProtocolPacket + Debug,
+ {
Connection {
- stream: self.stream,
- compression_threshold: self.compression_threshold,
- enc_cipher: self.enc_cipher,
- dec_cipher: self.dec_cipher,
+ stream: connection.stream,
+ compression_threshold: connection.compression_threshold,
+ enc_cipher: connection.enc_cipher,
+ dec_cipher: connection.dec_cipher,
_reading: PhantomData,
_writing: PhantomData,
}