return results instead of unwrapping
This commit is contained in:
parent
6757ad28f8
commit
40b38d0bec
|
@ -1,4 +1,4 @@
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn 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());
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn 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());
|
||||||
}
|
}
|
||||||
|
|
20
src/lib.rs
20
src/lib.rs
|
@ -11,12 +11,12 @@ pub mod http {
|
||||||
use crate::{Error, IpType, Provider};
|
use crate::{Error, IpType, Provider};
|
||||||
use std::default::Default;
|
use std::default::Default;
|
||||||
|
|
||||||
pub fn ipv4() -> http::Request<&'static [u8]> {
|
pub fn ipv4() -> Result<http::Request<&'static [u8]>, Error> {
|
||||||
ip(IpType::V4, Provider::default()).unwrap()
|
ip(IpType::V4, Provider::default())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn ipv6() -> http::Request<&'static [u8]> {
|
pub fn ipv6() -> Result<http::Request<&'static [u8]>, Error> {
|
||||||
ip(IpType::V6, Provider::default()).unwrap()
|
ip(IpType::V6, Provider::default())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn ip<T: Into<Provider>>(ip_type: IpType, provider: T) -> Result<http::Request<&'static [u8]>, Error> {
|
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::default::Default;
|
||||||
use std::convert::TryInto;
|
use std::convert::TryInto;
|
||||||
|
|
||||||
pub async fn ipv4(client: &mut Client) -> Ipv4Addr {
|
pub async fn ipv4(client: &mut Client) -> Result<Ipv4Addr, Error> {
|
||||||
match ip(client, IpType::V4, Provider::default()).await.unwrap() {
|
match ip(client, IpType::V4, Provider::default()).await? {
|
||||||
IpAddr::V4(ip) => ip,
|
IpAddr::V4(ip) => Ok(ip),
|
||||||
_ => {
|
_ => {
|
||||||
log::error!("This should be unreachable, if the provider is working and configured correctly");
|
log::error!("This should be unreachable, if the provider is working and configured correctly");
|
||||||
panic!();
|
panic!();
|
||||||
|
@ -44,9 +44,9 @@ pub mod reqwest_client {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn ipv6(client: &mut Client) -> Ipv6Addr {
|
pub async fn ipv6(client: &mut Client) -> Result<Ipv6Addr, Error> {
|
||||||
match ip(client, IpType::V6, Provider::default()).await.unwrap() {
|
match ip(client, IpType::V6, Provider::default()).await? {
|
||||||
IpAddr::V6(ip) => ip,
|
IpAddr::V6(ip) => Ok(ip),
|
||||||
_ => {
|
_ => {
|
||||||
log::error!("This should be unreachable, if the provider is working and configured correctly");
|
log::error!("This should be unreachable, if the provider is working and configured correctly");
|
||||||
panic!();
|
panic!();
|
||||||
|
|
Loading…
Reference in a new issue