mc_query/
lib.rs

1//! Implementations of [Server List ping](https://wiki.vg/Server_List_Ping),
2//! [Query](https://wiki.vg/Query), and [RCON](https://wiki.vg/RCON) using the
3//! Minecraft networking protocol.
4
5#![warn(missing_docs)]
6#![warn(clippy::pedantic)]
7#![allow(clippy::cast_possible_truncation)]
8#![allow(clippy::cast_possible_wrap)]
9#![allow(clippy::cast_sign_loss)]
10#![allow(clippy::cast_lossless)]
11
12macro_rules! create_timeout {
13    ($name:ident, $ret:ty) => {
14        ::paste::paste! {
15            #[doc = concat!("Similar to [`", stringify!($name), "`]")]
16            /// but with an added argument for timeout.
17            ///
18            /// Note that timeouts are not precise, and may vary on the order
19            /// of milliseconds, because of the way the async event loop works.
20            ///
21            /// # Arguments
22            /// * `host` - A string slice that holds the hostname of the server to connect to.
23            /// * `port` - The port to connect to on that server.
24            ///
25            /// # Errors
26            /// Returns `Err` on any condition that
27            #[doc = concat!("[`", stringify!($name), "`]")]
28            /// does, and also when the response is not fully recieved within `dur`.
29            pub async fn [<$name _with_timeout>](
30                host: &str,
31                port: u16,
32                dur: ::std::time::Duration,
33            ) -> ::std::io::Result<$ret> {
34                use crate::errors::timeout_err;
35                use ::tokio::time::timeout;
36
37                timeout(dur, $name(host, port))
38                    .await
39                    .unwrap_or(timeout_err::<$ret>())
40            }
41        }
42    };
43}
44
45pub mod errors;
46pub mod query;
47pub mod rcon;
48mod socket;
49pub mod status;
50mod varint;
51
52pub use status::status;