McClient

Struct McClient 

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

Implementations§

Source§

impl McClient

Source

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}
Source

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}
Source

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}
Source

pub async fn ping( &self, address: &str, edition: ServerEdition, ) -> Result<ServerStatus, McError>

Source

pub async fn ping_java(&self, address: &str) -> Result<ServerStatus, McError>

Source

pub async fn ping_bedrock(&self, address: &str) -> Result<ServerStatus, McError>

Source

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§

Source§

impl Clone for McClient

Source§

fn clone(&self) -> McClient

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Default for McClient

Source§

fn default() -> Self

Returns the “default value” for a type. 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, 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> 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.