From a9ff79a10553026b0fa32f0e31f1e0442467ca78 Mon Sep 17 00:00:00 2001 From: mat Date: Sun, 23 Oct 2022 14:46:06 -0500 Subject: write more documentation --- azalea-client/src/ping.rs | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) (limited to 'azalea-client/src/ping.rs') diff --git a/azalea-client/src/ping.rs b/azalea-client/src/ping.rs index c59fb3ac..6817677e 100755 --- a/azalea-client/src/ping.rs +++ b/azalea-client/src/ping.rs @@ -1,4 +1,5 @@ -///! Ping Minecraft servers. +//! Ping Minecraft servers. + use azalea_protocol::{ connect::{Connection, ConnectionError}, packets::{ @@ -25,12 +26,27 @@ pub enum PingError { ReadPacket(#[from] azalea_protocol::read::ReadPacketError), #[error("{0}")] WritePacket(#[from] io::Error), + #[error("The given address could not be parsed into a ServerAddress")] + InvalidAddress, } +/// Ping a Minecraft server. +/// +/// ``` +/// use azalea_client::ping; +/// +/// #[tokio::main] +/// async fn main() { +/// let response = ping::ping_server("play.hypixel.net").await.unwrap(); +/// println!("{}", response.description.to_ansi(None)); +/// } +/// ``` pub async fn ping_server( - address: &ServerAddress, + address: impl TryInto, ) -> Result { - let resolved_address = resolver::resolve_address(address).await?; + let address: ServerAddress = address.try_into().map_err(|_| PingError::InvalidAddress)?; + + let resolved_address = resolver::resolve_address(&address).await?; let mut conn = Connection::new(&resolved_address).await?; -- cgit v1.2.3