mry icon indicating copy to clipboard operation
mry copied to clipboard

Functions with lifetime argument can't be mocked

Open rayslava opened this issue 3 years ago • 7 comments

Functions like

#[mry::mry]
fn test<'a>(arg: &'a str) -> &'a str {
    arg
}

causes error[E0261]: use of undeclared lifetime name 'a, and removing #[mry::mry] fixes the error.

Is this a bug or there's some additional syntax for this case?

rayslava avatar Jun 10 '22 09:06 rayslava

Thanks for submitting. It’s just not implemented. I’ll fix this soon. Issues like this are helpful for making mry more mature.

ryo33 avatar Jun 10 '22 11:06 ryo33

Okay, I see. And thank you for the framework! It's really convenient and easy-to-use for small projects.

rayslava avatar Jun 10 '22 13:06 rayslava

I've published mry 0.2.4, the problem should be resolved. Please reopen this issue if not resolved. There are still many missing features in mry that I am not aware of, so I'm glad if you open issues for any problems with mry.

ryo33 avatar Jun 10 '22 17:06 ryo33

Still no success... Apparently I've created a code bad enough to brake your macros :) https://github.com/rayslava/ytdlpwui/runs/6866944541?check_suite_focus=true#step:7:82

rayslava avatar Jun 13 '22 18:06 rayslava

Oh, zero-copy things are a bit difficult in current mry features. It's because parameters must be 'static to be stored to call logs. I think we need an attribute like #[mry::into(StaticStruct)] to convert a value with not 'static lifetime into something 'static one.

ryo33 avatar Jun 14 '22 00:06 ryo33

We need, otherwise, something like #[mry::no_call_log)] to make call logs unavailable. Do you need to assert the function how called with assert_called? It uses call logs so needs 'static lifetime.

ryo33 avatar Jun 14 '22 00:06 ryo33

I've decided to support lifetime arguments in the future. I have thought about how to do it. It requires a few API changes.

ryo33 avatar Jul 15 '22 08:07 ryo33