From 42babea318ffed731aa916522208d136174025af Mon Sep 17 00:00:00 2001 From: Chris Tsang Date: Mon, 23 Oct 2023 10:08:32 +0100 Subject: [PATCH] Hotfix: conditionally impl impl_try_getable_array --- sea-orm-macros/src/derives/active_enum.rs | 26 +++++++++++++++-------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/sea-orm-macros/src/derives/active_enum.rs b/sea-orm-macros/src/derives/active_enum.rs index f163275f..41813499 100644 --- a/sea-orm-macros/src/derives/active_enum.rs +++ b/sea-orm-macros/src/derives/active_enum.rs @@ -290,6 +290,22 @@ impl ActiveEnum { quote!() }; + let impl_try_getable_array = if cfg!(feature = "postgres-array") { + quote!( + #[automatically_derived] + impl sea_orm::TryGetableArray for #ident { + fn try_get_by(res: &sea_orm::QueryResult, index: I) -> std::result::Result, sea_orm::TryGetError> { + <::Value as sea_orm::ActiveEnumValue>::try_get_vec_by(res, index)? + .into_iter() + .map(|value| ::try_from_value(&value).map_err(Into::into)) + .collect() + } + } + ) + } else { + quote!() + }; + quote!( #[doc = " Generated by sea-orm-macros"] #[derive(Debug, Clone, PartialEq, Eq)] @@ -337,15 +353,7 @@ impl ActiveEnum { } } - #[automatically_derived] - impl sea_orm::TryGetableArray for #ident { - fn try_get_by(res: &sea_orm::QueryResult, index: I) -> std::result::Result, sea_orm::TryGetError> { - <::Value as sea_orm::ActiveEnumValue>::try_get_vec_by(res, index)? - .into_iter() - .map(|value| ::try_from_value(&value).map_err(Into::into)) - .collect() - } - } + #impl_try_getable_array #[automatically_derived] #[allow(clippy::from_over_into)]