stevenarella
stevenarella copied to clipboard
impl From<Packet types> for Packet
Without impl Into, I have to write something like
let pkt = Packet::ClientSettings(
packet::play::serverbound::ClientSettings {
locale: "en_GB".to_string(),
view_distance: 2,
chat_mode: protocol::VarInt(0),
chat_colors: false,
displayed_skin_parts: 0,
main_hand: protocol::VarInt(0),
}
);
This commit makes the following code possible
let pkt: Packet = packet::play::serverbound::ClientSettings {
locale: "en_GB".to_string(),
view_distance: 2,
chat_mode: protocol::VarInt(0),
chat_colors: false,
displayed_skin_parts: 0,
main_hand: protocol::VarInt(0),
}.into();
It's more tidy
I think it would be better to implement From<$name> for Packet instead of Into<Packet> for $name
I think it would be better to implement
From<$name> for Packetinstead ofInto<Packet> for $name
Thanks for the advice @mpfaff , looks like I made a rookie mistake (
Implementing From automatically provides one with an implementation of Into, but implementing Into don't do the same thing
Implementing From automatically provides one with an implementation of Into, but implementing Into don't do the same thing
Hey, no worries! You're contributing to an open source project and from my perspective we're all here to learn.
As a side note, I used to implement Into by default because prior to Rust 1.41 you could not implement From for a type across crate boundaries so Into was the only option in a lot of cases.