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

Add support for lifetime in ref_into #19

Merged
merged 2 commits into from
Sep 4, 2024

Conversation

vnghia
Copy link
Contributor

@vnghia vnghia commented Aug 31, 2024

Hi @Artem-Romanenia, I am not sure how to add tests so could you help me 😅 ?

Closes: #16

@Artem-Romanenia
Copy link
Owner

Artem-Romanenia commented Aug 31, 2024

Hi @vnghia, so, the tests are in ./o2o-tests/tests folder. You can check existing tests, for example 18_where_attr_tests.rs (actual tests start at line 58), but you will see right away that they are hard to follow, because I was trying to test a bunch of related things in the same file, and I was defining structs at file level, and it's unreasonably hard to trace what maps with what...
For some time now I wanted to try new approach and define structs inside the test itself.

So, maybe start by creating a file 45_lifetime_tests.rs, and there you can start with a test like:

#[test]
fn ref_into_test() {
    #[derive(o2o::o2o)]
    #[ref_into(EntityDto<'a, 'b>)]
    pub struct Entity {
        #[into(~.as_str())]
        pub some_a: String,
        #[into(~.as_str())]
        pub some_b: String,
    }

    pub struct EntityDto<'a, 'b> {
        pub some_a: &'a str,
        pub some_b: &'b str,
    }

    let entity = &Entity {
        some_a: "A".into(),
        some_b: "B".into()
    };

    let dto: EntityDto = entity.into();

    // Assert that dto.some_a equals entity.some_a and so on
} 

Maybe we can also have a test exactly like that, but where one field has different name.

Then we would need a test for from_ref.

Then all the same tests, but where we map to 2 structs at the same time, like

    #[derive(o2o::o2o)]
    #[ref_into(EntityDto<'a, 'b>)]
    #[ref_into(AnotherEntityDto<'b, 'c>)]
    pub struct Entity {
        #[into(~.as_str())]
        pub some_a: String,
        #[into(~.as_str())]
        pub some_b: String,
    }

And then we would need a file 45_lifetime_tests_fallible.rs with all the same tests but this time for TryFrom and TryInto...

I'm currently running out of time, and I'm afraid I didn't make it any clearer for you, so maybe start with a couple of things, and then we'll see how it goes)

P.S. We would also need tests where we do 'compound' instructions, like "map" or "from" or "into", and check that ref conversions work without altering how 'non-ref' implementations are expanded...

@Artem-Romanenia
Copy link
Owner

Hi @vnghia, do you mind if I merge your changes in their current state and proceed from here myself?

@vnghia
Copy link
Contributor Author

vnghia commented Sep 4, 2024

Yeah please do it. I am intent to do something with it this weekend but I think you will have a better insight than me about adding tests and also some syntax confusions we dicussed in the issue.

@Artem-Romanenia
Copy link
Owner

Good, thanks a lot for your contribution! I'll post in #16 when there's a crate release with your changes

@Artem-Romanenia Artem-Romanenia merged commit be437b4 into Artem-Romanenia:main Sep 4, 2024
1 check passed
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.

Missing lifetime when doing from_ref
2 participants