pub struct McClient { /* private fields */ }Implementations§
Source§impl McClient
impl McClient
Sourcepub fn new() -> Self
pub fn new() -> Self
Examples found in repository?
examples/basic.rs (line 6)
5async fn main() -> Result<(), Box<dyn std::error::Error>> {
6 let client = McClient::new()
7 .with_timeout(Duration::from_secs(5))
8 .with_max_parallel(10);
9
10 // Ping multiple servers
11 let servers = vec![
12 ServerInfo {
13 address: "mc.hypixel.net:25565".to_string(),
14 edition: ServerEdition::Java,
15 },
16 ServerInfo {
17 address: "geo.hivebedrock.network:19132".to_string(),
18 edition: ServerEdition::Bedrock,
19 },
20 ];
21
22 let results = client.ping_many(&servers).await;
23
24 for (server, result) in results {
25 println!("\nChecking server: {}", server.address);
26 match result {
27 Ok(status) => {
28 println!("Status: Online ({} ms)", status.latency);
29 match status.data {
30 rust_mc_status::ServerData::Java(java) => {
31 println!("Name: {}", java.description);
32 println!("Version: {}", java.version.name);
33 println!("Players: {}/{}", java.players.online, java.players.max);
34
35 // Save favicon if available
36 let filename = format!("{}_favicon.png", server.address.replace(':', "_"));
37 match java.save_favicon(&filename) {
38 Ok(_) => println!("Favicon saved as {}", filename),
39 Err(e) => println!("Favicon not available: {}", e),
40 }
41 }
42 rust_mc_status::ServerData::Bedrock(bedrock) => {
43 println!("Name: {}", bedrock.motd);
44 println!("Version: {}", bedrock.version);
45 println!("Players: {}/{}", bedrock.online_players, bedrock.max_players);
46 println!("Favicon: Not supported in Bedrock");
47 }
48 }
49 }
50 Err(e) => println!("Status: Offline or error ({})", e),
51 }
52 }
53
54 Ok(())
55}Sourcepub fn with_timeout(self, timeout: Duration) -> Self
pub fn with_timeout(self, timeout: Duration) -> Self
Examples found in repository?
examples/basic.rs (line 7)
5async fn main() -> Result<(), Box<dyn std::error::Error>> {
6 let client = McClient::new()
7 .with_timeout(Duration::from_secs(5))
8 .with_max_parallel(10);
9
10 // Ping multiple servers
11 let servers = vec![
12 ServerInfo {
13 address: "mc.hypixel.net:25565".to_string(),
14 edition: ServerEdition::Java,
15 },
16 ServerInfo {
17 address: "geo.hivebedrock.network:19132".to_string(),
18 edition: ServerEdition::Bedrock,
19 },
20 ];
21
22 let results = client.ping_many(&servers).await;
23
24 for (server, result) in results {
25 println!("\nChecking server: {}", server.address);
26 match result {
27 Ok(status) => {
28 println!("Status: Online ({} ms)", status.latency);
29 match status.data {
30 rust_mc_status::ServerData::Java(java) => {
31 println!("Name: {}", java.description);
32 println!("Version: {}", java.version.name);
33 println!("Players: {}/{}", java.players.online, java.players.max);
34
35 // Save favicon if available
36 let filename = format!("{}_favicon.png", server.address.replace(':', "_"));
37 match java.save_favicon(&filename) {
38 Ok(_) => println!("Favicon saved as {}", filename),
39 Err(e) => println!("Favicon not available: {}", e),
40 }
41 }
42 rust_mc_status::ServerData::Bedrock(bedrock) => {
43 println!("Name: {}", bedrock.motd);
44 println!("Version: {}", bedrock.version);
45 println!("Players: {}/{}", bedrock.online_players, bedrock.max_players);
46 println!("Favicon: Not supported in Bedrock");
47 }
48 }
49 }
50 Err(e) => println!("Status: Offline or error ({})", e),
51 }
52 }
53
54 Ok(())
55}Sourcepub fn with_max_parallel(self, max_parallel: usize) -> Self
pub fn with_max_parallel(self, max_parallel: usize) -> Self
Examples found in repository?
examples/basic.rs (line 8)
5async fn main() -> Result<(), Box<dyn std::error::Error>> {
6 let client = McClient::new()
7 .with_timeout(Duration::from_secs(5))
8 .with_max_parallel(10);
9
10 // Ping multiple servers
11 let servers = vec![
12 ServerInfo {
13 address: "mc.hypixel.net:25565".to_string(),
14 edition: ServerEdition::Java,
15 },
16 ServerInfo {
17 address: "geo.hivebedrock.network:19132".to_string(),
18 edition: ServerEdition::Bedrock,
19 },
20 ];
21
22 let results = client.ping_many(&servers).await;
23
24 for (server, result) in results {
25 println!("\nChecking server: {}", server.address);
26 match result {
27 Ok(status) => {
28 println!("Status: Online ({} ms)", status.latency);
29 match status.data {
30 rust_mc_status::ServerData::Java(java) => {
31 println!("Name: {}", java.description);
32 println!("Version: {}", java.version.name);
33 println!("Players: {}/{}", java.players.online, java.players.max);
34
35 // Save favicon if available
36 let filename = format!("{}_favicon.png", server.address.replace(':', "_"));
37 match java.save_favicon(&filename) {
38 Ok(_) => println!("Favicon saved as {}", filename),
39 Err(e) => println!("Favicon not available: {}", e),
40 }
41 }
42 rust_mc_status::ServerData::Bedrock(bedrock) => {
43 println!("Name: {}", bedrock.motd);
44 println!("Version: {}", bedrock.version);
45 println!("Players: {}/{}", bedrock.online_players, bedrock.max_players);
46 println!("Favicon: Not supported in Bedrock");
47 }
48 }
49 }
50 Err(e) => println!("Status: Offline or error ({})", e),
51 }
52 }
53
54 Ok(())
55}pub async fn ping( &self, address: &str, edition: ServerEdition, ) -> Result<ServerStatus, McError>
pub async fn ping_java(&self, address: &str) -> Result<ServerStatus, McError>
pub async fn ping_bedrock(&self, address: &str) -> Result<ServerStatus, McError>
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>)>
Examples found in repository?
examples/basic.rs (line 22)
5async fn main() -> Result<(), Box<dyn std::error::Error>> {
6 let client = McClient::new()
7 .with_timeout(Duration::from_secs(5))
8 .with_max_parallel(10);
9
10 // Ping multiple servers
11 let servers = vec![
12 ServerInfo {
13 address: "mc.hypixel.net:25565".to_string(),
14 edition: ServerEdition::Java,
15 },
16 ServerInfo {
17 address: "geo.hivebedrock.network:19132".to_string(),
18 edition: ServerEdition::Bedrock,
19 },
20 ];
21
22 let results = client.ping_many(&servers).await;
23
24 for (server, result) in results {
25 println!("\nChecking server: {}", server.address);
26 match result {
27 Ok(status) => {
28 println!("Status: Online ({} ms)", status.latency);
29 match status.data {
30 rust_mc_status::ServerData::Java(java) => {
31 println!("Name: {}", java.description);
32 println!("Version: {}", java.version.name);
33 println!("Players: {}/{}", java.players.online, java.players.max);
34
35 // Save favicon if available
36 let filename = format!("{}_favicon.png", server.address.replace(':', "_"));
37 match java.save_favicon(&filename) {
38 Ok(_) => println!("Favicon saved as {}", filename),
39 Err(e) => println!("Favicon not available: {}", e),
40 }
41 }
42 rust_mc_status::ServerData::Bedrock(bedrock) => {
43 println!("Name: {}", bedrock.motd);
44 println!("Version: {}", bedrock.version);
45 println!("Players: {}/{}", bedrock.online_players, bedrock.max_players);
46 println!("Favicon: Not supported in Bedrock");
47 }
48 }
49 }
50 Err(e) => println!("Status: Offline or error ({})", e),
51 }
52 }
53
54 Ok(())
55}Trait Implementations§
Auto Trait Implementations§
impl Freeze for McClient
impl RefUnwindSafe for McClient
impl Send for McClient
impl Sync for McClient
impl Unpin for McClient
impl UnwindSafe 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
Mutably borrows from an owned value. Read more