mirror of https://github.com/astral-sh/uv
uv-normalize: add `as_str` method
`ExtraName` did implement `AsRef<str>`, but that should generally only be used in a context with an `AsRef<str>` generic bound. If you just want a `&str` from a concrete `ExtraName`, then a specific method for that purpose should be used.
This commit is contained in:
parent
6250b900b7
commit
fccd48ce61
|
|
@ -23,6 +23,11 @@ impl ExtraName {
|
||||||
pub fn new(name: String) -> Result<Self, InvalidNameError> {
|
pub fn new(name: String) -> Result<Self, InvalidNameError> {
|
||||||
validate_and_normalize_owned(name).map(Self)
|
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 {
|
impl FromStr for ExtraName {
|
||||||
|
|
@ -51,6 +56,6 @@ impl Display for ExtraName {
|
||||||
|
|
||||||
impl AsRef<str> for ExtraName {
|
impl AsRef<str> for ExtraName {
|
||||||
fn as_ref(&self) -> &str {
|
fn as_ref(&self) -> &str {
|
||||||
&self.0
|
self.as_str()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue