Rename ExprStringLiteral::as_unconcatenated_string() to ExprStringLiteral::as_single_part_string() (#16253)

This commit is contained in:
Alex Waygood 2025-02-19 16:06:57 +00:00 committed by GitHub
parent 97d0659ce3
commit 25920fe489
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 50 additions and 45 deletions

View file

@ -824,6 +824,17 @@ pub struct ExprFString {
pub value: FStringValue,
}
impl ExprFString {
/// Returns the single [`FString`] if the f-string isn't implicitly concatenated, [`None`]
/// otherwise.
pub const fn as_single_part_fstring(&self) -> Option<&FString> {
match &self.value.inner {
FStringValueInner::Single(FStringPart::FString(fstring)) => Some(fstring),
_ => None,
}
}
}
/// The value representing an [`ExprFString`].
#[derive(Clone, Debug, PartialEq)]
pub struct FStringValue {
@ -856,15 +867,6 @@ impl FStringValue {
matches!(self.inner, FStringValueInner::Concatenated(_))
}
/// Returns the single [`FString`] if the f-string isn't implicitly concatenated, [`None`]
/// otherwise.
pub fn as_single(&self) -> Option<&FString> {
match &self.inner {
FStringValueInner::Single(FStringPart::FString(fstring)) => Some(fstring),
_ => None,
}
}
/// Returns a slice of all the [`FStringPart`]s contained in this value.
pub fn as_slice(&self) -> &[FStringPart] {
match &self.inner {
@ -1290,7 +1292,7 @@ pub struct ExprStringLiteral {
impl ExprStringLiteral {
/// Return `Some(literal)` if the string only consists of a single `StringLiteral` part
/// (indicating that it is not implicitly concatenated). Otherwise, return `None`.
pub fn as_unconcatenated_literal(&self) -> Option<&StringLiteral> {
pub fn as_single_part_string(&self) -> Option<&StringLiteral> {
match &self.value.inner {
StringLiteralValueInner::Single(value) => Some(value),
StringLiteralValueInner::Concatenated(_) => None,
@ -1728,6 +1730,17 @@ pub struct ExprBytesLiteral {
pub value: BytesLiteralValue,
}
impl ExprBytesLiteral {
/// Return `Some(literal)` if the bytestring only consists of a single `BytesLiteral` part
/// (indicating that it is not implicitly concatenated). Otherwise, return `None`.
pub const fn as_single_part_bytestring(&self) -> Option<&BytesLiteral> {
match &self.value.inner {
BytesLiteralValueInner::Single(value) => Some(value),
BytesLiteralValueInner::Concatenated(_) => None,
}
}
}
/// The value representing a [`ExprBytesLiteral`].
#[derive(Clone, Debug, PartialEq)]
pub struct BytesLiteralValue {