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

support serde values #30

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Conversation

yanns
Copy link
Contributor

@yanns yanns commented Jun 29, 2022

When we already have Value, we can avoid using the Serialize trait. This allows us:

  • to avoid the usage of two panic!
  • to have faster code. No need to serialize the whole tree.

As an alternative, we could also make the following function public:

pub(crate) fn diff<'a>(lhs: &'a Value, rhs: &'a Value, config: Config) -> Vec<Difference<'a>>

lhs: &Value,
rhs: &Value,
config: Config,
) -> Result<(), String>
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm curious if we could use something like Any::downcast_ref instead. Then we wouldn't have to add a whole new function.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea!

I'm trying this:

pub fn assert_json_matches_no_panic<Lhs, Rhs>(
    lhs: &Lhs,
    rhs: &Rhs,
    config: Config,
) -> Result<(), String>
where
    Lhs: Serialize + Any,
    Rhs: Serialize + Any,

In that case, the lifetime of lhs and rhs is 'static. (https://doc.rust-lang.org/std/any/index.html)

Do you have another idea?

@yanns yanns mentioned this pull request Jun 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants