Tokio- Params - returns a value referencing data owned by the current function

close

Thanks you everyone

If you have a lifetime parameter on your return type and it doesn't come from any of your arguments, then you are doing it wrong, and you misunderstand how generics and/or ownership works.

Generic lifetime parameters, like all generic parameters, are chosen by the caller. There is no way a generic lifetime parameter can be chosen by the caller in a way that the address of a value local to your function could satisfy it.

You are also trying to return the address of a local, which is by definition wrong and won't compile. When your local variables go out of scope, they get destroyed, and you would have dangling references.

You should just return Box<dyn Trait> instead of references.

1 Like

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.