return results instead of unwrapping

This commit is contained in:
Jan Christian Grünhage 2020-04-19 16:31:35 +02:00
parent 6757ad28f8
commit 40b38d0bec
Signed by: jcgruenhage
GPG Key ID: 6594C449C633D10C
3 changed files with 12 additions and 12 deletions

View File

@ -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());
}

View File

@ -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());
}

View File

@ -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<http::Request<&'static [u8]>, Error> {
ip(IpType::V4, Provider::default())
}
pub fn ipv6() -> http::Request<&'static [u8]> {
ip(IpType::V6, Provider::default()).unwrap()
pub fn ipv6() -> Result<http::Request<&'static [u8]>, Error> {
ip(IpType::V6, Provider::default())
}
pub fn ip<T: Into<Provider>>(ip_type: IpType, provider: T) -> Result<http::Request<&'static [u8]>, 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<Ipv4Addr, Error> {
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<Ipv6Addr, Error> {
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!();