Skip to content

Commit b760ba7

Browse files
committed
replace FromStr with TryFrom for Uri & Authority
1 parent 39c25c2 commit b760ba7

File tree

5 files changed

+169
-138
lines changed

5 files changed

+169
-138
lines changed

benches/bench.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ extern crate http_req;
33
extern crate test;
44

55
use http_req::{request::Request, response::Response, uri::Uri};
6-
use std::{fs::File, io::Read, time::Duration};
6+
use std::{convert::TryFrom, fs::File, io::Read, time::Duration};
77
use test::Bencher;
88

99
#[bench]
@@ -23,7 +23,7 @@ const URI: &str = "https://www.rust-lang.org/";
2323
#[bench]
2424
fn request_send(b: &mut Bencher) {
2525
b.iter(|| {
26-
let uri = URI.parse::<Uri>().unwrap();
26+
let uri = Uri::try_from(URI).unwrap();
2727
let timeout = Some(Duration::from_secs(6));
2828
let mut writer = Vec::new();
2929

@@ -38,5 +38,5 @@ fn request_send(b: &mut Bencher) {
3838

3939
#[bench]
4040
fn parse_uri(b: &mut Bencher) {
41-
b.iter(|| URI.parse::<Uri>());
41+
b.iter(|| Uri::try_from(URI));
4242
}

examples/request_builder_get.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
use http_req::{request::RequestBuilder, tls, uri::Uri};
2-
use std::net::TcpStream;
2+
use std::{convert::TryFrom, net::TcpStream};
33

44
fn main() {
55
//Parse uri and assign it to variable `addr`
6-
let addr: Uri = "https://doc.rust-lang.org/".parse().unwrap();
6+
let addr: Uri = Uri::try_from("https://doc.rust-lang.org/").unwrap();
77

88
//Connect to remote host
99
let stream = TcpStream::connect((addr.host().unwrap(), addr.corr_port())).unwrap();

0 commit comments

Comments
 (0)