Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ extern crate rustc_version;
use rustc_version::{version, Version};

fn main() {
if version().unwrap() >= Version::parse("1.30.0").unwrap() {
let version = version().unwrap();
if version >= Version::parse("1.30.0").unwrap() {
println!("cargo:rustc-cfg=error_source");
}
if version >= Version::parse("1.34.0").unwrap() {
println!("cargo:rustc-cfg=try_from");
}
}
28 changes: 27 additions & 1 deletion src/client/connect/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
//! - The [`Connect`](Connect) trait and related types to build custom connectors.
use std::error::Error as StdError;
use std::{fmt, mem};
#[cfg(try_from)] use std::convert::TryFrom;

use bytes::{BufMut, Bytes, BytesMut};
use futures::Future;
Expand Down Expand Up @@ -251,6 +252,15 @@ impl Destination {
*/
}

#[cfg(try_from)]
impl TryFrom<Uri> for Destination {
type Error = ::error::Error;

fn try_from(uri: Uri) -> Result<Self, Self::Error> {
Destination::try_from_uri(uri)
}
}

impl Connected {
/// Create new `Connected` type with empty metadata.
pub fn new() -> Connected {
Expand Down Expand Up @@ -381,7 +391,7 @@ where

#[cfg(test)]
mod tests {
use super::{Connected, Destination};
use super::{Connected, Destination, TryFrom};

#[test]
fn test_destination_set_scheme() {
Expand Down Expand Up @@ -527,6 +537,22 @@ mod tests {
assert_eq!(dst.port(), None);
}

#[cfg(try_from)]
#[test]
fn test_try_from_destination() {
let uri: http::Uri = "http://hyper.rs".parse().expect("initial parse");
let result = Destination::try_from(uri);
assert_eq!(result.is_ok(), true);
}

#[cfg(try_from)]
#[test]
fn test_try_from_no_scheme() {
let uri: http::Uri = "hyper.rs".parse().expect("initial parse error");
let result = Destination::try_from(uri);
assert_eq!(result.is_err(), true);
}

#[derive(Clone, Debug, PartialEq)]
struct Ex1(usize);

Expand Down