From 996ef650cfc51dcb7888d2bf6ede99df5c4fc35a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9mie=20Drouet?= Date: Mon, 29 Jul 2024 17:29:11 +0200 Subject: [PATCH] refactor: stop returning impl (#449) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérémie Drouet --- .../src/mj_attributes_element/print.rs | 11 +++++++++-- .../mrml-core/src/mj_include/body/print.rs | 9 ++++++++- .../mrml-core/src/mj_include/head/print.rs | 9 ++++++++- packages/mrml-core/src/prelude/print.rs | 18 ++++++++++-------- 4 files changed, 35 insertions(+), 12 deletions(-) diff --git a/packages/mrml-core/src/mj_attributes_element/print.rs b/packages/mrml-core/src/mj_attributes_element/print.rs index 7e7a4312..4c56c3d2 100644 --- a/packages/mrml-core/src/mj_attributes_element/print.rs +++ b/packages/mrml-core/src/mj_attributes_element/print.rs @@ -1,13 +1,20 @@ -use crate::prelude::print::{PrintableAttributes, PrintableElement}; +use crate::prelude::{hash::Map, print::PrintableElement}; impl PrintableElement for super::MjAttributesElement { + type Attrs = Map; + type Children = (); + fn tag(&self) -> &str { self.name.as_str() } - fn attributes(&self) -> &impl PrintableAttributes { + fn attributes(&self) -> &Self::Attrs { &self.attributes } + + fn children(&self) -> &Self::Children { + &() + } } #[cfg(test)] diff --git a/packages/mrml-core/src/mj_include/body/print.rs b/packages/mrml-core/src/mj_include/body/print.rs index a9024f8c..9d985172 100644 --- a/packages/mrml-core/src/mj_include/body/print.rs +++ b/packages/mrml-core/src/mj_include/body/print.rs @@ -11,13 +11,20 @@ impl PrintableAttributes for super::MjIncludeBodyAttributes { } impl PrintableElement for super::MjIncludeBody { + type Attrs = super::MjIncludeBodyAttributes; + type Children = (); + fn tag(&self) -> &str { super::NAME } - fn attributes(&self) -> &impl PrintableAttributes { + fn attributes(&self) -> &Self::Attrs { &self.0.attributes } + + fn children(&self) -> &Self::Children { + &() + } } #[cfg(test)] diff --git a/packages/mrml-core/src/mj_include/head/print.rs b/packages/mrml-core/src/mj_include/head/print.rs index c2cbcb20..3f90b6f0 100644 --- a/packages/mrml-core/src/mj_include/head/print.rs +++ b/packages/mrml-core/src/mj_include/head/print.rs @@ -2,13 +2,20 @@ use super::MjIncludeHeadKind; use crate::prelude::print::{PrintableAttributes, PrintableElement}; impl PrintableElement for super::MjIncludeHead { + type Attrs = super::MjIncludeHeadAttributes; + type Children = (); + fn tag(&self) -> &str { super::NAME } - fn attributes(&self) -> &impl PrintableAttributes { + fn attributes(&self) -> &Self::Attrs { &self.0.attributes } + + fn children(&self) -> &Self::Children { + &() + } } impl PrintableAttributes for super::MjIncludeHeadAttributes { diff --git a/packages/mrml-core/src/prelude/print.rs b/packages/mrml-core/src/prelude/print.rs index 7bd017bb..edff73ba 100644 --- a/packages/mrml-core/src/prelude/print.rs +++ b/packages/mrml-core/src/prelude/print.rs @@ -53,15 +53,18 @@ impl PrintableChildren for Vec { impl PrintableElement for super::Component, A, C> { + type Attrs = A; + type Children = C; + fn tag(&self) -> &str { T::static_tag() } - fn attributes(&self) -> &impl PrintableAttributes { + fn attributes(&self) -> &Self::Attrs { &self.attributes } - fn children(&self) -> &impl PrintableChildren { + fn children(&self) -> &Self::Children { &self.children } } @@ -131,13 +134,12 @@ pub trait Printable { } pub trait PrintableElement { + type Attrs: PrintableAttributes; + type Children: PrintableChildren; + fn tag(&self) -> &str; - fn attributes(&self) -> &impl PrintableAttributes { - &() - } - fn children(&self) -> &impl PrintableChildren { - &() - } + fn attributes(&self) -> &Self::Attrs; + fn children(&self) -> &Self::Children; } impl Printable for E {