From 19a0b9a62deb6bea388a95519d79839a8fabff04 Mon Sep 17 00:00:00 2001 From: Jed Denlea Date: Wed, 16 Mar 2022 17:43:27 -0700 Subject: [PATCH] From impls of PathAndQuery and Authority for Uri A Uri may logically hold only an Authority or only a PathAndQuery. Should an application want to make such Uris, it would be easier to safely create them by first making just an Authority or just a PathAndQuery, then cheaply convert them directly into a Uri. --- src/uri/mod.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/uri/mod.rs b/src/uri/mod.rs index b79cb704..3881f82e 100644 --- a/src/uri/mod.rs +++ b/src/uri/mod.rs @@ -736,6 +736,28 @@ impl<'a> TryFrom<&'a Uri> for Uri { } } +/// Convert an `Authority` into a `Uri`. +impl From for Uri { + fn from(authority: Authority) -> Self { + Self { + scheme: Scheme::empty(), + authority, + path_and_query: PathAndQuery::empty(), + } + } +} + +/// Convert a `PathAndQuery` into a `Uri`. +impl From for Uri { + fn from(path_and_query: PathAndQuery) -> Self { + Self { + scheme: Scheme::empty(), + authority: Authority::empty(), + path_and_query, + } + } +} + /// Convert a `Uri` from parts /// /// # Examples