Skip to main content

JavaServerStatus

Struct JavaServerStatus 

Source
pub struct JavaServerStatus(/* private fields */);
Expand description

Typed wrapper around a Java Edition ServerStatus.

Implements StatusExt for common fields and serde::Serialize via #[serde(transparent)] — serialises identically to the inner ServerStatus.

§Accessing raw fields

Use .raw() to get the underlying ServerStatus directly, or match on ServerData::Java for the raw JavaStatus.

§Example

use rust_mc_status::{McClient, StatusExt};

let client = McClient::builder().build();
let s = client.java("mc.hypixel.net").await?;

println!("Version  : {}", s.version());
println!("Players  : {}", s.display_players());
println!("Latency  : {:.0} ms", s.latency_ms());
println!("MOTD     : {}", s.motd_clean());
println!("Cached   : {}", s.is_cached());

Implementations§

Source§

impl JavaServerStatus

Source

pub fn motd(&self) -> &str

Primary MOTD / description as returned by the server.

May contain §-color codes. Use motd_clean to strip them. Returns "" when the inner data is not Java (shouldn’t happen in normal usage).

Source

pub fn motd_clean(&self) -> String

Primary MOTD with all Minecraft §-formatting codes removed and whitespace normalised.

Equivalent to strip_formatting applied to motd.

Source

pub fn version(&self) -> &str

Server version name, e.g. "1.21.4" or "Requires MC 1.8 / 1.21".

Source

pub fn players_online(&self) -> i64

Number of players currently online as reported by the server.

Large networks often report custom inflated numbers here.

Source

pub fn players_max(&self) -> i64

Maximum player capacity as reported by the server.

Source

pub fn favicon(&self) -> Option<&str>

Base64-encoded 64×64 PNG favicon, if the server provides one.

The string may include a data:image/png;base64, prefix. Use save_favicon to decode and write to disk.

Source

pub fn save_favicon(&self, filename: &str) -> Result<(), McError>

Decode the favicon and write it to filename as a PNG file.

§Errors
  • [McError::Protocol] — no favicon available.
  • [McError::Protocol] — base64 decoding failed.
  • [McError::Io] — file could not be created or written.
Source

pub fn is_cached(&self) -> bool

true if this result was served from the response cache.

Cached responses have latency_ms() == 0.0 and reflect the server state at the time of the original ping, not the current moment. The maximum age is determined by the TTL passed to McClientBuilder::response_cache.

Source

pub fn raw(&self) -> &ServerStatus

Access the underlying ServerStatus directly.

Use this to access fields not surfaced by the typed accessors, such as dns, meta, or to match on ServerData for the full JavaStatus.

Trait Implementations§

Source§

impl Debug for JavaServerStatus

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for JavaServerStatus

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Serialize for JavaServerStatus

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StatusExt for JavaServerStatus

Source§

fn latency_ms(&self) -> f64

Round-trip latency in milliseconds. Read more
Source§

fn ip(&self) -> &str

Resolved IP address of the server, e.g. "172.65.197.160".
Source§

fn hostname(&self) -> &str

Original hostname as provided to the ping call, e.g. "mc.hypixel.net".
Source§

fn port(&self) -> u16

Port that was connected to, e.g. 25565.
Source§

fn is_online(&self) -> bool

true if the server responded successfully within the timeout.
Source§

fn display_players(&self) -> String

Formatted "online/max" player string, e.g. "21000/200000". Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more