mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-03 18:28:24 +00:00
Rename as_str
to to_str
(#8886)
This PR renames the method on `StringLiteralValue` from `as_str` to `to_str`. The main motivation is to follow the naming convention as described in the [Rust API Guidelines](https://rust-lang.github.io/api-guidelines/naming.html#ad-hoc-conversions-follow-as_-to_-into_-conventions-c-conv). This method can perform a string allocation in case the string is implicitly concatenated.
This commit is contained in:
parent
b28556d739
commit
ec7456bac0
38 changed files with 68 additions and 68 deletions
|
@ -24,7 +24,7 @@ where
|
|||
fn add_to_names<'a>(elts: &'a [Expr], names: &mut Vec<&'a str>, flags: &mut DunderAllFlags) {
|
||||
for elt in elts {
|
||||
if let Expr::StringLiteral(ast::ExprStringLiteral { value, .. }) = elt {
|
||||
names.push(value.as_str());
|
||||
names.push(value.to_str());
|
||||
} else {
|
||||
*flags |= DunderAllFlags::INVALID_OBJECT;
|
||||
}
|
||||
|
|
|
@ -1233,10 +1233,10 @@ impl StringLiteralValue {
|
|||
///
|
||||
/// Note that this will perform an allocation on the first invocation if the
|
||||
/// string value is implicitly concatenated.
|
||||
pub fn as_str(&self) -> &str {
|
||||
pub fn to_str(&self) -> &str {
|
||||
match &self.inner {
|
||||
StringLiteralValueInner::Single(value) => value.as_str(),
|
||||
StringLiteralValueInner::Concatenated(value) => value.as_str(),
|
||||
StringLiteralValueInner::Concatenated(value) => value.to_str(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1259,7 +1259,7 @@ impl PartialEq<String> for StringLiteralValue {
|
|||
|
||||
impl fmt::Display for StringLiteralValue {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
f.write_str(self.as_str())
|
||||
f.write_str(self.to_str())
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1331,7 +1331,7 @@ struct ConcatenatedStringLiteral {
|
|||
|
||||
impl ConcatenatedStringLiteral {
|
||||
/// Extracts a string slice containing the entire concatenated string.
|
||||
fn as_str(&self) -> &str {
|
||||
fn to_str(&self) -> &str {
|
||||
self.value
|
||||
.get_or_init(|| self.strings.iter().map(StringLiteral::as_str).collect())
|
||||
}
|
||||
|
@ -1354,7 +1354,7 @@ impl Debug for ConcatenatedStringLiteral {
|
|||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
f.debug_struct("ConcatenatedStringLiteral")
|
||||
.field("strings", &self.strings)
|
||||
.field("value", &self.as_str())
|
||||
.field("value", &self.to_str())
|
||||
.finish()
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue