pub struct PingResult {
pub data: ServerData,
pub latency: f64,
pub meta: HashMap<String, String>,
}Expand description
Raw result returned by a PingProtocol
before it is assembled into a ServerStatus.
Separating latency from data keeps the trait signature clean — protocol
implementations don’t need to embed timing inside their own models.
meta is a forward-compatibility escape hatch: protocol-specific fields
that don’t yet have a typed ServerData variant go here as key-value
strings. Once a field is stable enough to model properly, it graduates into
the appropriate ServerData variant and is removed from meta.
§Implementing a new protocol
use rust_mc_status::{PingResult, models::ServerData};
use rust_mc_status::protocol::{PingProtocol, ResolvedTarget};
use rust_mc_status::core::time::{start_timer, elapsed_ms};
use rust_mc_status::McError;
use std::time::Duration;
#[derive(Debug, Clone, Copy, Default)]
pub struct QueryProtocol;
impl PingProtocol for QueryProtocol {
fn name(&self) -> &'static str { "query" }
async fn ping(
&self,
target: &ResolvedTarget,
timeout: Duration,
proxy: Option<&rust_mc_status::ProxyConfig>,
) -> Result<PingResult, McError> {
let start = start_timer();
// … UDP handshake, stat request, parse response …
Ok(PingResult::new(
ServerData::Query(Default::default()),
elapsed_ms(start),
))
}
}Fields§
§data: ServerDataEdition-specific server data — Java, Bedrock, Legacy, or Query.
latency: f64Round-trip latency in milliseconds. Always ≥ 0 (measured with a
monotonic clock via core::time::elapsed_ms).
meta: HashMap<String, String>Protocol-specific extra fields not yet modelled in ServerData.
Keys should be short lowercase strings, e.g. "forge_version" or
"netty_channel_id". Forwarded verbatim into ServerStatus::meta.
Implementations§
Source§impl PingResult
impl PingResult
Sourcepub fn new(data: ServerData, latency: f64) -> Self
pub fn new(data: ServerData, latency: f64) -> Self
Create a PingResult with an empty meta map.
Use this for all current protocols — Java Modern and Bedrock expose
everything through typed ServerData variants.
Sourcepub fn with_meta(
data: ServerData,
latency: f64,
meta: impl Into<HashMap<String, String>>,
) -> Self
pub fn with_meta( data: ServerData, latency: f64, meta: impl Into<HashMap<String, String>>, ) -> Self
Create a PingResult with protocol-specific metadata.
Use this when a new protocol exposes fields that don’t yet have a
typed ServerData variant.
Trait Implementations§
Source§impl Clone for PingResult
impl Clone for PingResult
Source§fn clone(&self) -> PingResult
fn clone(&self) -> PingResult
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for PingResult
impl RefUnwindSafe for PingResult
impl Send for PingResult
impl Sync for PingResult
impl Unpin for PingResult
impl UnsafeUnpin for PingResult
impl UnwindSafe for PingResult
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