rust-mc-status 3.0.0

High-performance asynchronous Rust library for querying Minecraft server status (Java & Bedrock)
Documentation
//! [`StatusExt`] trait and Minecraft text formatting helpers.
//!
//! [`strip_formatting`] and [`truncate_str`] are pure string utilities defined
//! in [`core::fmt`](crate::core::fmt) and re-exported here for convenience.

pub use crate::core::fmt::{strip_formatting, truncate_str};

/// Common interface shared by [`JavaServerStatus`](super::JavaServerStatus)
/// and [`BedrockServerStatus`](super::BedrockServerStatus).
///
/// Provides access to the fields that exist on every successful ping result
/// regardless of edition.  Import this trait to call its methods:
///
/// ```rust,no_run
/// use rust_mc_status::{McClient, StatusExt};
///
/// # #[tokio::main] async fn main() -> Result<(), rust_mc_status::McError> {
/// let client = McClient::builder().build();
/// let s = client.java("mc.hypixel.net").await?;
///
/// // These methods come from StatusExt:
/// println!("{} ms", s.latency_ms() as u32);
/// println!("{}", s.display_players()); // "21000/200000"
/// println!("{}", s.ip());
/// println!("{}", s.hostname());
/// # Ok(()) }
/// ```
pub trait StatusExt {
    /// Round-trip latency in milliseconds.
    ///
    /// `0.0` for responses served from the response cache
    /// (check [`JavaServerStatus::is_cached`](super::JavaServerStatus::is_cached)).
    fn latency_ms(&self) -> f64;

    /// Resolved IP address of the server, e.g. `"172.65.197.160"`.
    fn ip(&self) -> &str;

    /// Original hostname as provided to the ping call, e.g. `"mc.hypixel.net"`.
    fn hostname(&self) -> &str;

    /// Port that was connected to, e.g. `25565`.
    fn port(&self) -> u16;

    /// `true` if the server responded successfully within the timeout.
    fn is_online(&self) -> bool;

    /// Formatted `"online/max"` player string, e.g. `"21000/200000"`.
    ///
    /// For edition-specific types use
    /// [`JavaServerStatus::players_online`](super::JavaServerStatus::players_online) /
    /// [`players_max`](super::JavaServerStatus::players_max) directly.
    fn display_players(&self) -> String;
}