From 140453c64978d5f78e13c3e0a7dbecb55e5e5dd2 Mon Sep 17 00:00:00 2001 From: Mike Cronce Date: Mon, 18 Jul 2022 21:33:32 -0400 Subject: [PATCH] Return `&str` from `BasicAuth::user_id()` and `BasicAuth::password()` (#249) Co-authored-by: Rob Ede --- actix-web-httpauth/CHANGES.md | 4 ++++ actix-web-httpauth/src/extractors/basic.rs | 8 ++++---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/actix-web-httpauth/CHANGES.md b/actix-web-httpauth/CHANGES.md index 1b72cee94..cd3f20e04 100644 --- a/actix-web-httpauth/CHANGES.md +++ b/actix-web-httpauth/CHANGES.md @@ -1,6 +1,10 @@ # Changes ## Unreleased - 2022-xx-xx +- `BasicAuth::user_id()` now returns a `&str`. [#249] +- `BasicAuth::password()` now returns a `&str`. [#249] + +[#249]: https://github.com/actix/actix-extras/pull/249 ## 0.7.0 - 2022-07-19 diff --git a/actix-web-httpauth/src/extractors/basic.rs b/actix-web-httpauth/src/extractors/basic.rs index 817cc5175..bad0df878 100644 --- a/actix-web-httpauth/src/extractors/basic.rs +++ b/actix-web-httpauth/src/extractors/basic.rs @@ -93,13 +93,13 @@ pub struct BasicAuth(Basic); impl BasicAuth { /// Returns client's user-ID. - pub fn user_id(&self) -> &Cow<'static, str> { - self.0.user_id() + pub fn user_id(&self) -> &str { + self.0.user_id().as_ref() } /// Returns client's password. - pub fn password(&self) -> Option<&Cow<'static, str>> { - self.0.password() + pub fn password(&self) -> Option<&str> { + self.0.password().map(|s| s.as_ref()) } }