fzyzcjy / flutter_rust_bridge

Flutter/Dart <-> Rust binding generator, feature-rich, but seamless and simple.
https://fzyzcjy.github.io/flutter_rust_bridge/
MIT License
4.12k stars 283 forks source link

support `pub struct IDb(pub Opaque<Surreal<Db>>)` #863

Closed huang12zheng closed 1 year ago

huang12zheng commented 1 year ago

I'm not sure if that mode is supported. Or how to support it

pub struct IDb(pub Opaque<Surreal<Db>>);
@sealed
class SurrealDb extends FrbOpaque {
  final Db bridge;
  SurrealDb.fromRaw(int ptr, int size, this.bridge) : super.unsafe(ptr, size);
  @override
  DropFnType get dropFn => bridge.dropOpaqueSurrealDb;  //  error

  @override
  ShareFnType get shareFn => bridge.shareOpaqueSurrealDb;

  @override
  OpaqueTypeFinalizer get staticFinalizer => bridge.SurrealDbFinalizer;
}

class IDb {
  final SurrealDb field0;

  IDb({
    required this.field0,
  });
}
fzyzcjy commented 1 year ago

Hmm looks like a bug.

/cc @rogurotus who implemented the wonderful Opaque feature - a naive guess, maybe we forget to trigger code generation for this case?

rogurotus commented 1 year ago

I was unable to reproduce the error. Can I take a look at the generated Db (frb api class)

huang12zheng commented 1 year ago

https://github.com/huang12zheng/flutter_rust_bridge_template/tree/reproduce_863 you can find object from native/src/surreal.rs To be honest, I just saw Opaque today. I probably don't understand the code generation properly @rogurotus

rogurotus commented 1 year ago

flutter_rust_bridge/frb_codegen/src/generator/rust/mod.rs line - 139

Yes, this is indeed a bug. related functions are generated for arguments, not for return type.

        lines += distinct_input_types (should be distinct_output_types)
            .iter()
            .map(|f| self.generate_related_funcs(f, ir_file))
            .collect();

until fixed, you can create an empty function:

pub fn touch(opauqe: Opaque<Surreal<Db>>) {}
github-actions[bot] commented 1 year ago

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.