pub trait NetworkConnection: Send + Sync {
// Required methods
fn compression(&self) -> Option<CompressionInfo>;
fn send_encoded(&self, packet: EncodedPacket);
fn send_encoded_bundle(&self, packets: Vec<EncodedPacket>);
fn disconnect_with_reason(&self, reason: TextComponent);
fn tick(&self);
fn latency(&self) -> i32;
fn close(&self);
fn closed(&self) -> bool;
}Expand description
An object-safe trait for player connections.
This abstracts the connection layer so that:
JavaConnectioncan handle real network traffic- Test connections (like
FlintConnection) can record events for assertions
§Object Safety
This trait uses type erasure for packet sending - packets must be pre-encoded
into EncodedPacket before being sent. The Player struct provides a generic
send_packet<P: ClientPacket>() helper that handles encoding.
Required Methods§
Sourcefn compression(&self) -> Option<CompressionInfo>
fn compression(&self) -> Option<CompressionInfo>
Returns compression info for packet encoding.
Returns None if compression is disabled (e.g., for test connections).
Sourcefn send_encoded(&self, packet: EncodedPacket)
fn send_encoded(&self, packet: EncodedPacket)
Sends a pre-encoded packet.
This is the object-safe method that accepts already-encoded packets.
Use Player::send_packet() for the generic version that handles encoding.
Sourcefn send_encoded_bundle(&self, packets: Vec<EncodedPacket>)
fn send_encoded_bundle(&self, packets: Vec<EncodedPacket>)
Sends multiple pre-encoded packets as an atomic bundle.
The implementation wraps the packets with bundle delimiter packets so
the client processes them together in a single game tick.
Use Player::send_bundle() for the generic version that handles encoding.
Sourcefn disconnect_with_reason(&self, reason: TextComponent)
fn disconnect_with_reason(&self, reason: TextComponent)
Disconnects the player with a reason.
Trait Implementations§
Source§impl From<Box<dyn NetworkConnection>> for PlayerConnection
impl From<Box<dyn NetworkConnection>> for PlayerConnection
Source§fn from(v: Box<dyn NetworkConnection>) -> PlayerConnection
fn from(v: Box<dyn NetworkConnection>) -> PlayerConnection
Source§impl NetworkConnection for Box<dyn NetworkConnection>
impl NetworkConnection for Box<dyn NetworkConnection>
Source§fn compression(&self) -> Option<CompressionInfo>
fn compression(&self) -> Option<CompressionInfo>
Source§fn send_encoded(&self, packet: EncodedPacket)
fn send_encoded(&self, packet: EncodedPacket)
Source§fn send_encoded_bundle(&self, packets: Vec<EncodedPacket>)
fn send_encoded_bundle(&self, packets: Vec<EncodedPacket>)
Source§fn disconnect_with_reason(&self, reason: TextComponent)
fn disconnect_with_reason(&self, reason: TextComponent)
Source§impl TryInto<Box<dyn NetworkConnection>> for PlayerConnection
impl TryInto<Box<dyn NetworkConnection>> for PlayerConnection
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".