Closed patmuk closed 2 weeks ago
IIRC we disable by default when the traits satisfies some condition (third party?) for sanity reasons. Try to put an empty #[frb]
on it, i.e. #[frb] impl Default ...
or try #[frb] fn default()
and see whether it works.
(We should have better doc for that!)
Oh there seems already have doc: https://cjycode.com/flutter_rust_bridge/guides/traits/implementations
Some trait implementations are ignored by default to avoid generating meaningless things to Dart side such as clone and deref. However, if a function is ignored while you want it, you can put arbitrary attributes on it to tell flutter_rust_bridge you want it. For example, #[frb] fn f() { .. } suffices. Attributes with real contents like #[frb(sync)] fn f() { .. } also works.
Ah, super :)
But it doesn't work for me ... maybe because of the RustAutoOpaque
? However, function is function ...
I tried it with #[frb]
and #[frb(sync)]
, note before impl MyTrait
and fn f()
.
In the doc, did you mean
impl MyTrait for MyStruct {
#[frb] // marker to have this translated to dart
fn f(&self, a: String) -> i32 { ... }
}
instead of
impl MyTrait for MyStruct {
fn f(&self, a: String) -> i32 { ... }
}
?
Hmm...
Firstly, the workaround is to make another function (that calls this trait method).
Secondly, feel free to debug and fix it! I am happy to provide hints if you like.
In the doc, did you mean
If it is a custom trait (unlike Default etc) then it already works, without any extra #[frb]
I checked frb_example and default
seems to work. For example, this one in frb_example/pure_dart:
is auto generated from:
Thus close this issue, but feel free to reopen if you have any questions!
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new issue.
Is your feature request related to a problem? Please describe. In the following struct I implemented Default:
While there is a constructor
There is no
default()
method available. Asitems
isRustAutoOpaque
I can't initialize it on the Dart side (VecString
).Describe the solution you'd like Translating the
default()
function from the Trait to a Dart call as well. If possible doing so for all trait functions.Describe alternatives you've considered I am currently figuring out how I can do this without a
default()
call :)Additional context