wireguard_conf/macros.rs
1/// Get expression as [`ipnet::IpNet`]
2///
3/// Shorthand for `expr.parse::<IpNet>().unwrap()`
4///
5/// # Examples
6///
7/// ```rust
8/// use wireguard_conf::as_ipnet;
9/// use ipnet::IpNet;
10///
11/// # fn main() {
12/// assert_eq!(as_ipnet!("1.2.3.4/24"), "1.2.3.4/24".parse().unwrap());
13/// assert_eq!(as_ipnet!("fd00:DEAD:BEEF::1/24"), "fd00:DEAD:BEEF::1/24".parse().unwrap());
14/// # }
15/// ```
16#[macro_export]
17macro_rules! as_ipnet {
18 ($x:expr) => {
19 $x.parse::<$crate::ipnet::IpNet>().unwrap()
20 };
21}
22
23/// Get expression as [`std::net::IpAddr`]
24///
25/// Shorthand for `expr.parse::<IpAddr>().unwrap()`
26///
27/// # Examples
28///
29/// ```rust
30/// use wireguard_conf::as_ipaddr;
31/// use std::net::IpAddr;
32///
33/// # fn main() {
34/// assert_eq!(as_ipaddr!("1.2.3.4"), "1.2.3.4".parse::<IpAddr>().unwrap());
35/// assert_eq!(as_ipaddr!("fd00:DEAD:BEEF::1"), "fd00:DEAD:BEEF::1".parse::<IpAddr>().unwrap());
36/// # }
37/// ```
38#[macro_export]
39macro_rules! as_ipaddr {
40 ($x:expr) => {
41 $x.parse::<::std::net::IpAddr>().unwrap()
42 };
43}