use crate::prelude::*; use ruff_formatter::{FormatOwnedWithRule, FormatRefWithRule}; use ruff_python_ast::Operator; #[derive(Copy, Clone)] pub struct FormatOperator; impl<'ast> AsFormat> for Operator { type Format<'a> = FormatRefWithRule<'a, Operator, FormatOperator, PyFormatContext<'ast>>; fn format(&self) -> Self::Format<'_> { FormatRefWithRule::new(self, FormatOperator) } } impl<'ast> IntoFormat> for Operator { type Format = FormatOwnedWithRule>; fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self, FormatOperator) } } impl FormatRule> for FormatOperator { fn fmt(&self, item: &Operator, f: &mut PyFormatter) -> FormatResult<()> { let operator = match item { Operator::Add => "+", Operator::Sub => "-", Operator::Mult => "*", Operator::MatMult => "@", Operator::Div => "/", Operator::Mod => "%", Operator::Pow => "**", Operator::LShift => "<<", Operator::RShift => ">>", Operator::BitOr => "|", Operator::BitXor => "^", Operator::BitAnd => "&", Operator::FloorDiv => "//", }; token(operator).fmt(f) } }