Skip to content

Commit

Permalink
refactor: stop returning impl (#449)
Browse files Browse the repository at this point in the history
Signed-off-by: Jérémie Drouet <jeremie.drouet@gmail.com>
  • Loading branch information
jdrouet authored Jul 29, 2024
1 parent e375d4a commit 996ef65
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 12 deletions.
11 changes: 9 additions & 2 deletions packages/mrml-core/src/mj_attributes_element/print.rs
Original file line number Diff line number Diff line change
@@ -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<String, String>;
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)]
Expand Down
9 changes: 8 additions & 1 deletion packages/mrml-core/src/mj_include/body/print.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
9 changes: 8 additions & 1 deletion packages/mrml-core/src/mj_include/head/print.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
18 changes: 10 additions & 8 deletions packages/mrml-core/src/prelude/print.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,18 @@ impl<C: Printable> PrintableChildren for Vec<C> {
impl<T: StaticTag, A: PrintableAttributes, C: PrintableChildren> PrintableElement
for super::Component<PhantomData<T>, 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
}
}
Expand Down Expand Up @@ -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<E: PrintableElement> Printable for E {
Expand Down

0 comments on commit 996ef65

Please sign in to comment.