Open normalllll opened 2 months ago
Hmm, is it solved by https://github.com/fzyzcjy/flutter_rust_bridge/pull/2189?
Try:
/other/my_trait.rs
use std::future::Future;
pub trait MyTrait {
fn f1() -> impl Future<Output=anyhow::Result<String>>;
}
/other/subcrate/my_struct1.rs
pub struct MyStruct1 {}
impl MyTrait for MyStruct1 {
fn f1() -> impl Future<Output=anyhow::Result<String>> {
async {
Ok(String::from("hello"))
}
}
}
Generated: /other/subcrate/my_struct1.dart
// This file is automatically generated, so please do not edit it.
// Generated by `flutter_rust_bridge`@ 2.1.0.
// ignore_for_file: invalid_use_of_internal_member, unused_import, unnecessary_import
import '../../frb_generated.dart';
import 'package:flutter_rust_bridge/flutter_rust_bridge_for_generated.dart';
class MyStruct1 {
const MyStruct1();
@override
int get hashCode => 0;
@override
bool operator ==(Object other) =>
identical(this, other) ||
other is MyStruct1 && runtimeType == other.runtimeType;
}
Traits not in /api/* are still skipped.
That PR is ongoing, thus I mean does it solve your problem after it is implemented and merged?
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
The frb will skip traits with #[async_trait]. The specific manifestation is that a non-existent file is imported into dart (the file where the trait is located) or there are no methods in the struct.
When they are all in the /api crate
They can be produced normally.
When they are in different crates.
/api/some.rs
use async_trait::async_trait; use create::...;
/other/my_struct1.rs
/other/my_trait.rs
/api/some.dart
/some/my_struct1.dart