Skip to main content

McClient

Struct McClient 

Source
pub struct McClient { /* private fields */ }
Expand description

Async client for pinging Minecraft Java and Bedrock servers.

Constructed via McClient::builder() — there is no new(). Cheaply Clone-able — all clones share the same DNS/SRV and response caches.

§Example

use rust_mc_status::McClient;
use std::time::Duration;

let client = McClient::builder()
    .timeout(Duration::from_secs(5))
    .max_parallel(20)
    .response_cache(Duration::from_secs(30), 256)
    .build();

let status = client.java("mc.hypixel.net").await?;

Implementations§

Source§

impl McClient

Source

pub fn builder() -> McClientBuilder

Return a McClientBuilder — the only way to construct a McClient.

Source

pub fn timeout(&self) -> Duration

Returns the configured request timeout.

Source

pub fn max_parallel(&self) -> usize

Returns the configured maximum number of concurrent pings in ping_many.

Source

pub async fn clear_caches(&self)

Clear the DNS and SRV caches.

The next ping to any host will re-resolve DNS from scratch. The response cache is unaffected — use clear_response_cache to clear it separately.

Source

pub async fn clear_response_cache(&self)

Clear the response cache only.

The next ping to any cached server will perform a live network request. DNS/SRV caches are unaffected.

Source

pub async fn cache_stats(&self) -> CacheStats

Return a snapshot of current cache entry counts.

Useful for monitoring and debugging — does not block any in-flight pings.

Source

pub fn java(&self, address: impl Into<String>) -> JavaPingBuilder

Start a Java Edition ping for address.

Returns a JavaPingBuilder — call .await to execute, or chain .timeout(Duration) to override the timeout for this request only.

§Errors

The returned future may fail with:

§Example
use rust_mc_status::{McClient, StatusExt};
use std::time::Duration;

let client = McClient::builder().build();

// Default timeout
let s = client.java("mc.hypixel.net").await?;

// Per-request timeout
let s = client.java("mc.hypixel.net")
    .timeout(Duration::from_secs(3))
    .await?;
Source

pub fn bedrock(&self, address: impl Into<String>) -> BedrockPingBuilder

Start a Bedrock Edition ping for address.

Returns a BedrockPingBuilder — call .await to execute, or chain .timeout(Duration) to override the timeout for this request only.

§Errors

The returned future may fail with:

  • McError::Config — if address is malformed.
  • McError::Network — DNS failure, UDP send/receive error, or timeout.
  • McError::Protocol — pong packet too short or malformed MOTD.
  • [McError::Proxy] — proxy does not support UDP (feature = “proxy”).
§Example
use rust_mc_status::{McClient, StatusExt};

let client = McClient::builder().build();
let s = client.bedrock("geo.hivebedrock.network:19132").await?;
println!("{} — {}", s.edition(), s.display_players());
Source

pub fn server( &self, address: impl Into<String>, edition: ServerEdition, ) -> ServerPingBuilder

Start a ping where the edition is chosen at runtime.

Useful when edition comes from user input or a config file. Returns a ServerPingBuilder — call .await for a raw ServerStatus, or .is_online().await for a simple boolean reachability check.

§Example
use rust_mc_status::{McClient, ServerEdition};
use std::time::Duration;

let client = McClient::builder().build();
let edition: ServerEdition = "java".parse()?;

let online = client
    .server("mc.hypixel.net", edition)
    .timeout(Duration::from_secs(5))
    .is_online()
    .await;

println!("online: {online}");
Source

pub async fn ping_many( &self, servers: &[ServerInfo], ) -> Vec<(ServerInfo, Result<ServerStatus, McError>)>

Ping multiple servers concurrently with bounded parallelism.

All tasks are spawned immediately — a Semaphore limits how many run at once (max_parallel, default 10). Results are streamed back as they complete so a slow or timed-out server never blocks the rest.

When the response cache is enabled, duplicate addresses in the list benefit from in-flight deduplication — only one real ping is made per unique key regardless of how many times it appears.

§Return value

A Vec of (ServerInfo, Result<ServerStatus, McError>) pairs in completion order (not input order). Each entry either contains the full ServerStatus or the error that occurred for that server.

All tasks are spawned immediately — a Semaphore limits how many run at once. Results stream back as they complete, so a slow or timed-out server never blocks the rest.

Duplicate addresses benefit from in-flight deduplication when the response cache is enabled.

Trait Implementations§

Source§

impl Clone for McClient

Source§

fn clone(&self) -> McClient

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. 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