From fccd48ce61aac601c76c97fb3ced9a35ca83581f Mon Sep 17 00:00:00 2001 From: Andrew Gallant Date: Mon, 30 Sep 2024 14:15:48 -0400 Subject: [PATCH] uv-normalize: add `as_str` method `ExtraName` did implement `AsRef`, but that should generally only be used in a context with an `AsRef` generic bound. If you just want a `&str` from a concrete `ExtraName`, then a specific method for that purpose should be used. --- crates/uv-normalize/src/extra_name.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/crates/uv-normalize/src/extra_name.rs b/crates/uv-normalize/src/extra_name.rs index 6341ff7fe..f23431178 100644 --- a/crates/uv-normalize/src/extra_name.rs +++ b/crates/uv-normalize/src/extra_name.rs @@ -23,6 +23,11 @@ impl ExtraName { pub fn new(name: String) -> Result { validate_and_normalize_owned(name).map(Self) } + + /// Return the underlying extra name as a string. + pub fn as_str(&self) -> &str { + &self.0 + } } impl FromStr for ExtraName { @@ -51,6 +56,6 @@ impl Display for ExtraName { impl AsRef for ExtraName { fn as_ref(&self) -> &str { - &self.0 + self.as_str() } }