Macro rubedo_macros::ip
source · ip!() { /* proc-macro */ }
Expand description
Builds an IP address from a range of input types.
This macro provides syntactic sugar to build an IpAddr
from a range of
input types.
If left empty, it will default to 0.0.0.0
.
At present only IPv4 is supported, as this is the most common and the clearest use of this shorthand syntax. IPv6 support might be added in the future.
§Panics
Note that this macro will panic if it fails to parse a string literal as an
IP address. This is by design, so that all variants of IP creation return an
IpAddr
instance, just like IpAddr::from()
. This macro is intended to
be used with hard-coded addresses. If you need to handle errors, use the
standard IpAddr::from_str()
method instead.
§Examples
use rubedo_macros::ip;
use std::net::IpAddr;
assert_eq!(ip!(1.2.3.4), IpAddr::from([1, 2, 3, 4]));
assert_eq!(ip!("1.2.3.4"), IpAddr::from([1, 2, 3, 4]));
assert_eq!(ip!(1, 2, 3, 4), IpAddr::from([1, 2, 3, 4]));