From 5f4bce6d2b627efaf120d9f26b3acdcee6b75db2 Mon Sep 17 00:00:00 2001 From: Micha Reiser Date: Thu, 1 Jun 2023 12:20:49 +0200 Subject: [PATCH] Implement `IntoFormat` for `&T` (#4781) --- crates/ruff_formatter/shared_traits.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/crates/ruff_formatter/shared_traits.rs b/crates/ruff_formatter/shared_traits.rs index f427934f31..aab0120ea7 100644 --- a/crates/ruff_formatter/shared_traits.rs +++ b/crates/ruff_formatter/shared_traits.rs @@ -44,6 +44,18 @@ where } } +/// Implement [`IntoFormat`] for references to types that implement [`AsFormat`]. +impl<'a, T, C> IntoFormat for &'a T +where + T: AsFormat, +{ + type Format = T::Format<'a>; + + fn into_format(self) -> Self::Format { + AsFormat::format(self) + } +} + /// Formatting specific [`Iterator`] extensions pub trait FormattedIterExt { /// Converts every item to an object that knows how to format it.