diff options
| author | EightFactorial <murphkev000@gmail.com> | 2023-01-30 16:18:14 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-01-30 18:18:14 -0600 |
| commit | 6e818852d868eea963dd2b8489ba75b65c56fb1c (patch) | |
| tree | e786e919de7d4a1777d91e8e2fa890482970972d /azalea-protocol/src/lib.rs | |
| parent | 2539f948c7a88a86b27b1878f6c28976285f348c (diff) | |
| download | azalea-drasl-6e818852d868eea963dd2b8489ba75b65c56fb1c.tar.xz | |
More packet fixes, tests, handle error (#61)
* Fix packet, fix tests, fixedbitsets
* Clippy: Nightmare Mode
* Fix mistake
* simplify impl Display and make thing pub
---------
Co-authored-by: mat <github@matdoes.dev>
Diffstat (limited to 'azalea-protocol/src/lib.rs')
| -rw-r--r-- | azalea-protocol/src/lib.rs | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/azalea-protocol/src/lib.rs b/azalea-protocol/src/lib.rs index 3f838d2a..7c21f493 100644 --- a/azalea-protocol/src/lib.rs +++ b/azalea-protocol/src/lib.rs @@ -1,7 +1,7 @@ //! A low-level crate to send and receive Minecraft packets. //! //! You should probably use [`azalea`] or [`azalea_client`] instead, as -//! azalea_protocol delegates much of the work, such as auth, to the user of +//! `azalea_protocol` delegates much of the work, such as auth, to the user of //! the crate. //! //! [`azalea`]: https://crates.io/crates/azalea @@ -13,7 +13,7 @@ #![feature(error_generic_member_access)] #![feature(provide_any)] -use std::{net::SocketAddr, str::FromStr}; +use std::{fmt::Display, net::SocketAddr, str::FromStr}; #[cfg(feature = "connecting")] pub mod connect; @@ -27,7 +27,7 @@ pub mod write; /// /// # Examples /// -/// ServerAddress implements TryFrom<&str>, so you can use it like this: +/// `ServerAddress` implements TryFrom<&str>, so you can use it like this: /// ``` /// use azalea_protocol::ServerAddress; /// @@ -45,7 +45,7 @@ impl<'a> TryFrom<&'a str> for ServerAddress { type Error = String; /// Convert a Minecraft server address (host:port, the port is optional) to - /// a ServerAddress + /// a `ServerAddress` fn try_from(string: &str) -> Result<Self, Self::Error> { if string.is_empty() { return Err("Empty string".to_string()); @@ -60,9 +60,9 @@ impl<'a> TryFrom<&'a str> for ServerAddress { } impl From<SocketAddr> for ServerAddress { - /// Convert an existing SocketAddr into a ServerAddress. This just converts - /// the ip to a string and passes along the port. The resolver will realize - /// it's already an IP address and not do any DNS requests. + /// Convert an existing `SocketAddr` into a `ServerAddress`. This just + /// converts the ip to a string and passes along the port. The resolver + /// will realize it's already an IP address and not do any DNS requests. fn from(addr: SocketAddr) -> Self { ServerAddress { host: addr.ip().to_string(), @@ -71,6 +71,12 @@ impl From<SocketAddr> for ServerAddress { } } +impl Display for ServerAddress { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "{}:{}", self.host, self.port) + } +} + #[cfg(test)] mod tests { use std::io::Cursor; |
