mirror of
https://github.com/tribufu/rust-gamedig
synced 2026-05-18 09:35:50 +00:00
[Crate] Changed all address &str to &Ipv4Addr
This commit is contained in:
parent
a69896f737
commit
e620398615
65 changed files with 171 additions and 93 deletions
|
|
@ -4,6 +4,7 @@ use crate::{
|
|||
};
|
||||
|
||||
use std::cmp::Ordering;
|
||||
use std::net::Ipv4Addr;
|
||||
|
||||
pub fn error_by_expected_size(expected: usize, size: usize) -> GDResult<()> {
|
||||
match size.cmp(&expected) {
|
||||
|
|
@ -13,16 +14,18 @@ pub fn error_by_expected_size(expected: usize, size: usize) -> GDResult<()> {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn address_and_port_as_string(address: &str, port: u16) -> String { format!("{}:{}", address, port) }
|
||||
pub fn address_and_port_as_string(address: &Ipv4Addr, port: u16) -> String { format!("{}:{}", address, port) }
|
||||
|
||||
pub fn u8_lower_upper(n: u8) -> (u8, u8) { (n & 15, n >> 4) }
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use std::net::Ipv4Addr;
|
||||
|
||||
#[test]
|
||||
fn address_and_port_as_string() {
|
||||
assert_eq!(
|
||||
super::address_and_port_as_string("192.168.0.1", 27015),
|
||||
super::address_and_port_as_string(&Ipv4Addr::new(192, 168, 0, 1), 27015),
|
||||
"192.168.0.1:27015"
|
||||
);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue