McClient

Struct McClient 

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

Implementations§

Source§

impl McClient

Source

pub fn new() -> Self

Examples found in repository?
examples/advanced_usage.rs (line 9)
8async fn main() -> Result<(), Box<dyn std::error::Error>> {
9    let client = McClient::new()
10        .with_timeout(Duration::from_secs(5))
11        .with_max_parallel(10);
12
13    // List of servers to check
14    let servers = vec![
15        ServerInfo {
16            address: "mc.hypixel.net".to_string(),
17            edition: ServerEdition::Java,
18        },
19        ServerInfo {
20            address: "geo.hivebedrock.network:19132".to_string(),
21            edition: ServerEdition::Bedrock,
22        },
23        ServerInfo {
24            address: "mc233.cn".to_string(),
25            edition: ServerEdition::Java,
26        },
27    ];
28
29    println!("Requesting status for {} servers...", servers.len());
30    let results = client.ping_many(&servers).await;
31
32    for (server, result) in results {
33        println!("\n{}", "=".repeat(50));
34        println!("Server: {} ({:?})", server.address, server.edition);
35
36        match result {
37            Ok(status) => {
38                println!("Status: ✅ Online (latency: {:.2} ms)", status.latency);
39                println!("IP: {}, Port: {}", status.ip, status.port);
40                println!("Hostname: {}", status.hostname);
41
42                // DNS information
43                if let Some(dns) = status.dns {
44                    println!(
45                        "DNS: A-records: {:?}, CNAME: {:?}",
46                        dns.a_records, dns.cname
47                    );
48                }
49
50                // Processing data depending on server type
51                match status.data {
52                    mc_server_status::ServerData::Java(java_status) => {
53                        println!(
54                            "Version: {} (protocol: {})",
55                            java_status.version.name, java_status.version.protocol
56                        );
57                        println!(
58                            "Players: {}/{}",
59                            java_status.players.online, java_status.players.max
60                        );
61                        println!("Description: {}", java_status.description);
62
63                        // Используем ссылку вместо перемещения
64                        if let Some(ref map) = java_status.map {
65                            println!("Map: {}", map);
66                        }
67
68                        if let Some(ref gamemode) = java_status.gamemode {
69                            println!("Game mode: {}", gamemode);
70                        }
71
72                        if let Some(ref software) = java_status.software {
73                            println!("Server software: {}", software);
74                        }
75
76                        // Plugins and mods
77                        if let Some(ref plugins) = java_status.plugins {
78                            println!("Plugins ({}):", plugins.len());
79                            for plugin in plugins.iter().take(5) {
80                                println!(
81                                    "  - {} {}",
82                                    plugin.name,
83                                    plugin.version.as_deref().unwrap_or("")
84                                );
85                            }
86                            if plugins.len() > 5 {
87                                println!("  ... and {} more", plugins.len() - 5);
88                            }
89                        }
90
91                        if let Some(ref mods) = java_status.mods {
92                            println!("Mods ({}):", mods.len());
93                            for mod_ in mods.iter().take(5) {
94                                println!(
95                                    "  - {} {}",
96                                    mod_.modid,
97                                    mod_.version.as_deref().unwrap_or("")
98                                );
99                            }
100                            if mods.len() > 5 {
101                                println!("  ... and {} more", mods.len() - 5);
102                            }
103                        }
104
105                        // Saving icon
106                        if let Some(ref _favicon) = java_status.favicon {
107                            if let Err(e) = java_status.save_favicon("server_icon.png") {
108                                println!("Failed to save icon: {}", e);
109                            } else {
110                                println!("Icon saved as server_icon.png");
111                            }
112                        }
113                    }
114                    mc_server_status::ServerData::Bedrock(bedrock_status) => {
115                        println!("Edition: {}", bedrock_status.edition);
116                        println!("Version: {}", bedrock_status.version);
117                        println!(
118                            "Players: {}/{}",
119                            bedrock_status.online_players, bedrock_status.max_players
120                        );
121                        println!("MOTD: {}", bedrock_status.motd);
122
123                        if let Some(ref map) = bedrock_status.map {
124                            println!("Map: {}", map);
125                        }
126
127                        if let Some(ref software) = bedrock_status.software {
128                            println!("Server software: {}", software);
129                        }
130
131                        println!(
132                            "Game mode: {} ({})",
133                            bedrock_status.game_mode, bedrock_status.game_mode_numeric
134                        );
135                    }
136                }
137            }
138            Err(e) => {
139                println!("Status: ❌ Error: {}", e);
140            }
141        }
142    }
143
144    Ok(())
145}
Source

pub fn with_timeout(self, timeout: Duration) -> Self

Examples found in repository?
examples/advanced_usage.rs (line 10)
8async fn main() -> Result<(), Box<dyn std::error::Error>> {
9    let client = McClient::new()
10        .with_timeout(Duration::from_secs(5))
11        .with_max_parallel(10);
12
13    // List of servers to check
14    let servers = vec![
15        ServerInfo {
16            address: "mc.hypixel.net".to_string(),
17            edition: ServerEdition::Java,
18        },
19        ServerInfo {
20            address: "geo.hivebedrock.network:19132".to_string(),
21            edition: ServerEdition::Bedrock,
22        },
23        ServerInfo {
24            address: "mc233.cn".to_string(),
25            edition: ServerEdition::Java,
26        },
27    ];
28
29    println!("Requesting status for {} servers...", servers.len());
30    let results = client.ping_many(&servers).await;
31
32    for (server, result) in results {
33        println!("\n{}", "=".repeat(50));
34        println!("Server: {} ({:?})", server.address, server.edition);
35
36        match result {
37            Ok(status) => {
38                println!("Status: ✅ Online (latency: {:.2} ms)", status.latency);
39                println!("IP: {}, Port: {}", status.ip, status.port);
40                println!("Hostname: {}", status.hostname);
41
42                // DNS information
43                if let Some(dns) = status.dns {
44                    println!(
45                        "DNS: A-records: {:?}, CNAME: {:?}",
46                        dns.a_records, dns.cname
47                    );
48                }
49
50                // Processing data depending on server type
51                match status.data {
52                    mc_server_status::ServerData::Java(java_status) => {
53                        println!(
54                            "Version: {} (protocol: {})",
55                            java_status.version.name, java_status.version.protocol
56                        );
57                        println!(
58                            "Players: {}/{}",
59                            java_status.players.online, java_status.players.max
60                        );
61                        println!("Description: {}", java_status.description);
62
63                        // Используем ссылку вместо перемещения
64                        if let Some(ref map) = java_status.map {
65                            println!("Map: {}", map);
66                        }
67
68                        if let Some(ref gamemode) = java_status.gamemode {
69                            println!("Game mode: {}", gamemode);
70                        }
71
72                        if let Some(ref software) = java_status.software {
73                            println!("Server software: {}", software);
74                        }
75
76                        // Plugins and mods
77                        if let Some(ref plugins) = java_status.plugins {
78                            println!("Plugins ({}):", plugins.len());
79                            for plugin in plugins.iter().take(5) {
80                                println!(
81                                    "  - {} {}",
82                                    plugin.name,
83                                    plugin.version.as_deref().unwrap_or("")
84                                );
85                            }
86                            if plugins.len() > 5 {
87                                println!("  ... and {} more", plugins.len() - 5);
88                            }
89                        }
90
91                        if let Some(ref mods) = java_status.mods {
92                            println!("Mods ({}):", mods.len());
93                            for mod_ in mods.iter().take(5) {
94                                println!(
95                                    "  - {} {}",
96                                    mod_.modid,
97                                    mod_.version.as_deref().unwrap_or("")
98                                );
99                            }
100                            if mods.len() > 5 {
101                                println!("  ... and {} more", mods.len() - 5);
102                            }
103                        }
104
105                        // Saving icon
106                        if let Some(ref _favicon) = java_status.favicon {
107                            if let Err(e) = java_status.save_favicon("server_icon.png") {
108                                println!("Failed to save icon: {}", e);
109                            } else {
110                                println!("Icon saved as server_icon.png");
111                            }
112                        }
113                    }
114                    mc_server_status::ServerData::Bedrock(bedrock_status) => {
115                        println!("Edition: {}", bedrock_status.edition);
116                        println!("Version: {}", bedrock_status.version);
117                        println!(
118                            "Players: {}/{}",
119                            bedrock_status.online_players, bedrock_status.max_players
120                        );
121                        println!("MOTD: {}", bedrock_status.motd);
122
123                        if let Some(ref map) = bedrock_status.map {
124                            println!("Map: {}", map);
125                        }
126
127                        if let Some(ref software) = bedrock_status.software {
128                            println!("Server software: {}", software);
129                        }
130
131                        println!(
132                            "Game mode: {} ({})",
133                            bedrock_status.game_mode, bedrock_status.game_mode_numeric
134                        );
135                    }
136                }
137            }
138            Err(e) => {
139                println!("Status: ❌ Error: {}", e);
140            }
141        }
142    }
143
144    Ok(())
145}
Source

pub fn with_max_parallel(self, max_parallel: usize) -> Self

Examples found in repository?
examples/advanced_usage.rs (line 11)
8async fn main() -> Result<(), Box<dyn std::error::Error>> {
9    let client = McClient::new()
10        .with_timeout(Duration::from_secs(5))
11        .with_max_parallel(10);
12
13    // List of servers to check
14    let servers = vec![
15        ServerInfo {
16            address: "mc.hypixel.net".to_string(),
17            edition: ServerEdition::Java,
18        },
19        ServerInfo {
20            address: "geo.hivebedrock.network:19132".to_string(),
21            edition: ServerEdition::Bedrock,
22        },
23        ServerInfo {
24            address: "mc233.cn".to_string(),
25            edition: ServerEdition::Java,
26        },
27    ];
28
29    println!("Requesting status for {} servers...", servers.len());
30    let results = client.ping_many(&servers).await;
31
32    for (server, result) in results {
33        println!("\n{}", "=".repeat(50));
34        println!("Server: {} ({:?})", server.address, server.edition);
35
36        match result {
37            Ok(status) => {
38                println!("Status: ✅ Online (latency: {:.2} ms)", status.latency);
39                println!("IP: {}, Port: {}", status.ip, status.port);
40                println!("Hostname: {}", status.hostname);
41
42                // DNS information
43                if let Some(dns) = status.dns {
44                    println!(
45                        "DNS: A-records: {:?}, CNAME: {:?}",
46                        dns.a_records, dns.cname
47                    );
48                }
49
50                // Processing data depending on server type
51                match status.data {
52                    mc_server_status::ServerData::Java(java_status) => {
53                        println!(
54                            "Version: {} (protocol: {})",
55                            java_status.version.name, java_status.version.protocol
56                        );
57                        println!(
58                            "Players: {}/{}",
59                            java_status.players.online, java_status.players.max
60                        );
61                        println!("Description: {}", java_status.description);
62
63                        // Используем ссылку вместо перемещения
64                        if let Some(ref map) = java_status.map {
65                            println!("Map: {}", map);
66                        }
67
68                        if let Some(ref gamemode) = java_status.gamemode {
69                            println!("Game mode: {}", gamemode);
70                        }
71
72                        if let Some(ref software) = java_status.software {
73                            println!("Server software: {}", software);
74                        }
75
76                        // Plugins and mods
77                        if let Some(ref plugins) = java_status.plugins {
78                            println!("Plugins ({}):", plugins.len());
79                            for plugin in plugins.iter().take(5) {
80                                println!(
81                                    "  - {} {}",
82                                    plugin.name,
83                                    plugin.version.as_deref().unwrap_or("")
84                                );
85                            }
86                            if plugins.len() > 5 {
87                                println!("  ... and {} more", plugins.len() - 5);
88                            }
89                        }
90
91                        if let Some(ref mods) = java_status.mods {
92                            println!("Mods ({}):", mods.len());
93                            for mod_ in mods.iter().take(5) {
94                                println!(
95                                    "  - {} {}",
96                                    mod_.modid,
97                                    mod_.version.as_deref().unwrap_or("")
98                                );
99                            }
100                            if mods.len() > 5 {
101                                println!("  ... and {} more", mods.len() - 5);
102                            }
103                        }
104
105                        // Saving icon
106                        if let Some(ref _favicon) = java_status.favicon {
107                            if let Err(e) = java_status.save_favicon("server_icon.png") {
108                                println!("Failed to save icon: {}", e);
109                            } else {
110                                println!("Icon saved as server_icon.png");
111                            }
112                        }
113                    }
114                    mc_server_status::ServerData::Bedrock(bedrock_status) => {
115                        println!("Edition: {}", bedrock_status.edition);
116                        println!("Version: {}", bedrock_status.version);
117                        println!(
118                            "Players: {}/{}",
119                            bedrock_status.online_players, bedrock_status.max_players
120                        );
121                        println!("MOTD: {}", bedrock_status.motd);
122
123                        if let Some(ref map) = bedrock_status.map {
124                            println!("Map: {}", map);
125                        }
126
127                        if let Some(ref software) = bedrock_status.software {
128                            println!("Server software: {}", software);
129                        }
130
131                        println!(
132                            "Game mode: {} ({})",
133                            bedrock_status.game_mode, bedrock_status.game_mode_numeric
134                        );
135                    }
136                }
137            }
138            Err(e) => {
139                println!("Status: ❌ Error: {}", e);
140            }
141        }
142    }
143
144    Ok(())
145}
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/advanced_usage.rs (line 30)
8async fn main() -> Result<(), Box<dyn std::error::Error>> {
9    let client = McClient::new()
10        .with_timeout(Duration::from_secs(5))
11        .with_max_parallel(10);
12
13    // List of servers to check
14    let servers = vec![
15        ServerInfo {
16            address: "mc.hypixel.net".to_string(),
17            edition: ServerEdition::Java,
18        },
19        ServerInfo {
20            address: "geo.hivebedrock.network:19132".to_string(),
21            edition: ServerEdition::Bedrock,
22        },
23        ServerInfo {
24            address: "mc233.cn".to_string(),
25            edition: ServerEdition::Java,
26        },
27    ];
28
29    println!("Requesting status for {} servers...", servers.len());
30    let results = client.ping_many(&servers).await;
31
32    for (server, result) in results {
33        println!("\n{}", "=".repeat(50));
34        println!("Server: {} ({:?})", server.address, server.edition);
35
36        match result {
37            Ok(status) => {
38                println!("Status: ✅ Online (latency: {:.2} ms)", status.latency);
39                println!("IP: {}, Port: {}", status.ip, status.port);
40                println!("Hostname: {}", status.hostname);
41
42                // DNS information
43                if let Some(dns) = status.dns {
44                    println!(
45                        "DNS: A-records: {:?}, CNAME: {:?}",
46                        dns.a_records, dns.cname
47                    );
48                }
49
50                // Processing data depending on server type
51                match status.data {
52                    mc_server_status::ServerData::Java(java_status) => {
53                        println!(
54                            "Version: {} (protocol: {})",
55                            java_status.version.name, java_status.version.protocol
56                        );
57                        println!(
58                            "Players: {}/{}",
59                            java_status.players.online, java_status.players.max
60                        );
61                        println!("Description: {}", java_status.description);
62
63                        // Используем ссылку вместо перемещения
64                        if let Some(ref map) = java_status.map {
65                            println!("Map: {}", map);
66                        }
67
68                        if let Some(ref gamemode) = java_status.gamemode {
69                            println!("Game mode: {}", gamemode);
70                        }
71
72                        if let Some(ref software) = java_status.software {
73                            println!("Server software: {}", software);
74                        }
75
76                        // Plugins and mods
77                        if let Some(ref plugins) = java_status.plugins {
78                            println!("Plugins ({}):", plugins.len());
79                            for plugin in plugins.iter().take(5) {
80                                println!(
81                                    "  - {} {}",
82                                    plugin.name,
83                                    plugin.version.as_deref().unwrap_or("")
84                                );
85                            }
86                            if plugins.len() > 5 {
87                                println!("  ... and {} more", plugins.len() - 5);
88                            }
89                        }
90
91                        if let Some(ref mods) = java_status.mods {
92                            println!("Mods ({}):", mods.len());
93                            for mod_ in mods.iter().take(5) {
94                                println!(
95                                    "  - {} {}",
96                                    mod_.modid,
97                                    mod_.version.as_deref().unwrap_or("")
98                                );
99                            }
100                            if mods.len() > 5 {
101                                println!("  ... and {} more", mods.len() - 5);
102                            }
103                        }
104
105                        // Saving icon
106                        if let Some(ref _favicon) = java_status.favicon {
107                            if let Err(e) = java_status.save_favicon("server_icon.png") {
108                                println!("Failed to save icon: {}", e);
109                            } else {
110                                println!("Icon saved as server_icon.png");
111                            }
112                        }
113                    }
114                    mc_server_status::ServerData::Bedrock(bedrock_status) => {
115                        println!("Edition: {}", bedrock_status.edition);
116                        println!("Version: {}", bedrock_status.version);
117                        println!(
118                            "Players: {}/{}",
119                            bedrock_status.online_players, bedrock_status.max_players
120                        );
121                        println!("MOTD: {}", bedrock_status.motd);
122
123                        if let Some(ref map) = bedrock_status.map {
124                            println!("Map: {}", map);
125                        }
126
127                        if let Some(ref software) = bedrock_status.software {
128                            println!("Server software: {}", software);
129                        }
130
131                        println!(
132                            "Game mode: {} ({})",
133                            bedrock_status.game_mode, bedrock_status.game_mode_numeric
134                        );
135                    }
136                }
137            }
138            Err(e) => {
139                println!("Status: ❌ Error: {}", e);
140            }
141        }
142    }
143
144    Ok(())
145}

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,