diff --git a/crates/ruff_python_ast/src/nodes.rs b/crates/ruff_python_ast/src/nodes.rs index babba89fc2..66aff7b654 100644 --- a/crates/ruff_python_ast/src/nodes.rs +++ b/crates/ruff_python_ast/src/nodes.rs @@ -1087,6 +1087,24 @@ pub struct FStringFormatSpec { pub elements: Vec, } +impl FStringFormatSpec { + /// Returns an iterator over all the [`FStringLiteralElement`] nodes contained in this format + /// spec of the f-string. + pub fn literals(&self) -> impl Iterator { + self.elements + .iter() + .filter_map(|element| element.as_literal()) + } + + /// Returns an iterator over all the [`FStringExpressionElement`] nodes contained in this + /// format spec of the f-string. + pub fn expressions(&self) -> impl Iterator { + self.elements + .iter() + .filter_map(|element| element.as_expression()) + } +} + impl Ranged for FStringFormatSpec { fn range(&self) -> TextRange { self.range