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
impl McClient
Sourcepub fn builder() -> McClientBuilder
pub fn builder() -> McClientBuilder
Return a McClientBuilder — the only way to construct a McClient.
Sourcepub fn max_parallel(&self) -> usize
pub fn max_parallel(&self) -> usize
Returns the configured maximum number of concurrent pings in ping_many.
Sourcepub async fn clear_caches(&self)
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.
Sourcepub async fn clear_response_cache(&self)
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.
Sourcepub async fn cache_stats(&self) -> CacheStats
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.
Sourcepub fn java(&self, address: impl Into<String>) -> JavaPingBuilder
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:
McError::Config— ifaddressis malformed (bad port, missing]).McError::Network— DNS failure, connection refused, or timeout.McError::Protocol— unexpected server response.
§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?;Sourcepub fn bedrock(&self, address: impl Into<String>) -> BedrockPingBuilder
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— ifaddressis 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());Sourcepub fn server(
&self,
address: impl Into<String>,
edition: ServerEdition,
) -> ServerPingBuilder
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}");Sourcepub async fn ping_many(
&self,
servers: &[ServerInfo],
) -> Vec<(ServerInfo, Result<ServerStatus, McError>)>
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§
Auto Trait Implementations§
impl !RefUnwindSafe for McClient
impl !UnwindSafe for McClient
impl Freeze for McClient
impl Send for McClient
impl Sync for McClient
impl Unpin for McClient
impl UnsafeUnpin for McClient
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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