uniffi-rs icon indicating copy to clipboard operation
uniffi-rs copied to clipboard

Is there a way to use `impl Into<T>` in function arguments?

Open srfsh opened this issue 7 months ago • 2 comments
trafficstars

I am trying to utilize the Into trait in my function, however I encounter an error like this (the new function mentioned here is an #[uniffi::constructor]:

error[E0562]: `impl Trait` is not allowed in paths
  --> config.rs:23:23
   |
23 |     pub fn new(data_dir: impl Into<PathBuf>, cache_dir: impl Into<PathBuf>) -> Self {
   |                          ^^^^^^^^^^^^^^^^^
   |
   = note: `impl Trait` is only allowed in arguments and return types of functions and methods

Is there a reason why this isn't working, and are there any ways I can make it work?

srfsh avatar Apr 24 '25 19:04 srfsh

It can't really work in general, because the signature exposed by the bindings needs to be one of the "primitive" types for that language - ie, something needs to know that this would translate to "String" on the foreign side. I guess it might be possible to support some "well known" traits though.

mhammond avatar Apr 24 '25 20:04 mhammond

I agree. That would benefit the developer experience greatly.

srfsh avatar Apr 24 '25 20:04 srfsh