From 40b38d0bec2d02d1b8adccaf98461579c44774cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Christian=20Gr=C3=BCnhage?= Date: Sun, 19 Apr 2020 16:31:35 +0200 Subject: [PATCH] return results instead of unwrapping --- src/bin/yapilt4.rs | 2 +- src/bin/yapilt6.rs | 2 +- src/lib.rs | 20 ++++++++++---------- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/bin/yapilt4.rs b/src/bin/yapilt4.rs index 6f36fb8..2a73ba9 100644 --- a/src/bin/yapilt4.rs +++ b/src/bin/yapilt4.rs @@ -1,4 +1,4 @@ #[tokio::main] async fn main() { - println!("{}", yapilt::reqwest_client::ipv4(&mut reqwest::Client::new()).await); + println!("{}", yapilt::reqwest_client::ipv4(&mut reqwest::Client::new()).await.unwrap()); } diff --git a/src/bin/yapilt6.rs b/src/bin/yapilt6.rs index 49f28a4..906dca8 100644 --- a/src/bin/yapilt6.rs +++ b/src/bin/yapilt6.rs @@ -1,4 +1,4 @@ #[tokio::main] async fn main() { - println!("{}", yapilt::reqwest_client::ipv6(&mut reqwest::Client::new()).await); + println!("{}", yapilt::reqwest_client::ipv6(&mut reqwest::Client::new()).await.unwrap()); } diff --git a/src/lib.rs b/src/lib.rs index d995399..128fc77 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -11,12 +11,12 @@ pub mod http { use crate::{Error, IpType, Provider}; use std::default::Default; - pub fn ipv4() -> http::Request<&'static [u8]> { - ip(IpType::V4, Provider::default()).unwrap() + pub fn ipv4() -> Result, Error> { + ip(IpType::V4, Provider::default()) } - pub fn ipv6() -> http::Request<&'static [u8]> { - ip(IpType::V6, Provider::default()).unwrap() + pub fn ipv6() -> Result, Error> { + ip(IpType::V6, Provider::default()) } pub fn ip>(ip_type: IpType, provider: T) -> Result, Error> { @@ -34,9 +34,9 @@ pub mod reqwest_client { use std::default::Default; use std::convert::TryInto; - pub async fn ipv4(client: &mut Client) -> Ipv4Addr { - match ip(client, IpType::V4, Provider::default()).await.unwrap() { - IpAddr::V4(ip) => ip, + pub async fn ipv4(client: &mut Client) -> Result { + match ip(client, IpType::V4, Provider::default()).await? { + IpAddr::V4(ip) => Ok(ip), _ => { log::error!("This should be unreachable, if the provider is working and configured correctly"); panic!(); @@ -44,9 +44,9 @@ pub mod reqwest_client { } } - pub async fn ipv6(client: &mut Client) -> Ipv6Addr { - match ip(client, IpType::V6, Provider::default()).await.unwrap() { - IpAddr::V6(ip) => ip, + pub async fn ipv6(client: &mut Client) -> Result { + match ip(client, IpType::V6, Provider::default()).await? { + IpAddr::V6(ip) => Ok(ip), _ => { log::error!("This should be unreachable, if the provider is working and configured correctly"); panic!();