Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: stop returning impl in print feature #449

Merged
merged 1 commit into from
Jul 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading