Skip to content

Commit

Permalink
From impls of PathAndQuery and Authority for Uri
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jeddenlea committed Mar 17, 2022
1 parent c28945c commit 19a0b9a
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/uri/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -736,6 +736,28 @@ impl<'a> TryFrom<&'a Uri> for Uri {
}
}

/// Convert an `Authority` into a `Uri`.
impl From<Authority> 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<PathAndQuery> 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
Expand Down

0 comments on commit 19a0b9a

Please sign in to comment.