mirror of
https://github.com/tribufu/rust-gamedig
synced 2026-05-06 15:27:28 +00:00
[Protocol] Enable the use of Ipv6 addresses (#41)
Replace usages of Ipv4Addr with IpAddr which allows the use of either Ipv4 or Ipv6. This patch essentially consists of running: "sed -i 's/Ipv4Addr/IpAddr/g' src/**/*.rs examples/*" and fixing the errors.
This commit is contained in:
parent
e620398615
commit
3f654e0dfd
60 changed files with 155 additions and 162 deletions
|
|
@ -4,7 +4,7 @@ use crate::{
|
|||
};
|
||||
|
||||
use std::cmp::Ordering;
|
||||
use std::net::Ipv4Addr;
|
||||
use std::net::IpAddr;
|
||||
|
||||
pub fn error_by_expected_size(expected: usize, size: usize) -> GDResult<()> {
|
||||
match size.cmp(&expected) {
|
||||
|
|
@ -14,18 +14,18 @@ pub fn error_by_expected_size(expected: usize, size: usize) -> GDResult<()> {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn address_and_port_as_string(address: &Ipv4Addr, port: u16) -> String { format!("{}:{}", address, port) }
|
||||
pub fn address_and_port_as_string(address: &IpAddr, 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;
|
||||
use std::net::{IpAddr, Ipv4Addr};
|
||||
|
||||
#[test]
|
||||
fn address_and_port_as_string() {
|
||||
assert_eq!(
|
||||
super::address_and_port_as_string(&Ipv4Addr::new(192, 168, 0, 1), 27015),
|
||||
super::address_and_port_as_string(&IpAddr::V4(Ipv4Addr::new(192, 168, 0, 1)), 27015),
|
||||
"192.168.0.1:27015"
|
||||
);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue