aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRichard Walters <rwalters@digitalstirling.com>2020-10-12 15:30:55 -0700
committerRichard Walters <rwalters@digitalstirling.com>2020-10-12 15:30:55 -0700
commit877401cfa7c2885ee34c58917c4f7d26a25a2146 (patch)
tree5d870632e4a726870ff2415c4d0b6cff6a9b6f38 /src
parent1ba4fc897985564f2debeb4b369d2da9b3671263 (diff)
Clean up Uri::host
Diffstat (limited to 'src')
-rw-r--r--src/lib.rs26
1 files changed, 3 insertions, 23 deletions
diff --git a/src/lib.rs b/src/lib.rs
index e5c4804..554a4a2 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -642,29 +642,9 @@ impl Uri {
#[must_use = "why u no use host return value?"]
pub fn host(&self) -> Option<&[u8]> {
- // Here is another way to do the same thing, but with some Rust-fu.
- // Credit goes to everx80, ABuffSeagull, and silen_z:
- //
- // self.authority
- // .as_ref()
- // .and_then(
- // |authority| authority.host.as_deref()
- // )
- //
- // * First `as_ref` gets our authority from `&Option<Authority>` into
- // `Option<&Authority>` (there is an implicit borrow of
- // `self.authority` first).
- // * Next, `and_then` basically converts `Option<&Authority>`
- // into `Option<&[u8]>` by leveraging the closure we provide
- // to convert `&Authority` into `Option<&[u8]>`.
- // * Finally, our closure uses `as_deref` to turn our `Option<Vec<u8>>`
- // into an `Option<&[u8]>` since Vec<T> implements DeRef with
- // `Target=[T]`
- if let Some(authority) = &self.authority {
- Some(authority.host())
- } else {
- None
- }
+ self.authority
+ .as_ref()
+ .map(Authority::host)
}
fn is_path_absolute(path: &[Vec<u8>]) -> bool {