From 226990584b523184b493d84451b27f97e983b135 Mon Sep 17 00:00:00 2001 From: Sergio Benitez Date: Wed, 11 Apr 2018 10:46:15 -0700 Subject: [PATCH] Implement 'UriDisplay' for 'str', 'RawStr' directly. --- lib/src/http/uri/from_uri_param.rs | 20 +++++++++++++------- lib/src/http/uri/uri_display.rs | 6 +++--- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/lib/src/http/uri/from_uri_param.rs b/lib/src/http/uri/from_uri_param.rs index 644f4277..f0fa9d71 100644 --- a/lib/src/http/uri/from_uri_param.rs +++ b/lib/src/http/uri/from_uri_param.rs @@ -32,13 +32,19 @@ use http::uri::UriDisplay; /// /// # Implementing /// -/// Because Rocket provides a blanket implementation for all types, this trait -/// typically does not need to be implemented. This trait should only be -/// implemented when you'd like to allow a type different from the route's -/// declared type to be used in its place in a `uri!` invocation. This is -/// typically only warranted for owned-value types with corresponding reference -/// types: `String` and `&str`, for instance. In this case, it's desireable to -/// allow an `&str` to be used in place of a `String`. +/// Rocket provides a blanket implementation for all types that implement +/// [`UriDisplay`]. As such, this trait typically does not need to be implemented. +/// Instead, implement [`UriDisplay`]. +/// +/// This trait should only be implemented when you'd like to allow a type +/// different from the route's declared type to be used in its place in a `uri!` +/// invocation. For instance, if the route has a type of `T` and you'd like to +/// use a type of `S` in a `uri!` invocation, you'd implement `FromUriParam +/// for S`. +/// +/// This is typically only warranted for owned-value types with +/// corresponding reference types: `String` and `&str`, for instance. In this +/// case, it's desireable to allow an `&str` to be used in place of a `String`. /// /// When implementing `FromUriParam`, be aware that Rocket will use the /// [`UriDisplay`] implementation of `Target`, _not_ of the source type. diff --git a/lib/src/http/uri/uri_display.rs b/lib/src/http/uri/uri_display.rs index a4f49ddd..3bdf717a 100644 --- a/lib/src/http/uri/uri_display.rs +++ b/lib/src/http/uri/uri_display.rs @@ -165,7 +165,7 @@ impl<'a> fmt::Display for &'a UriDisplay { } /// Percent-encodes the raw string. -impl<'a> UriDisplay for &'a RawStr { +impl UriDisplay for RawStr { #[inline(always)] fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{}", Uri::percent_encode((*self).as_str())) @@ -173,7 +173,7 @@ impl<'a> UriDisplay for &'a RawStr { } /// Percent-encodes the raw string. -impl<'a> UriDisplay for &'a str { +impl UriDisplay for str { #[inline(always)] fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{}", Uri::percent_encode(self)) @@ -207,7 +207,7 @@ impl UriDisplay for PathBuf { } /// Percent-encodes each segment in the path. -impl<'a> UriDisplay for &'a Path { +impl UriDisplay for Path { #[inline(always)] fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { let string = self.to_string_lossy();