From b82a49046e97fb4761fac68b73e02466cb33d92f Mon Sep 17 00:00:00 2001 From: fzyzcjy Date: Thu, 12 Sep 2024 09:09:53 +0800 Subject: [PATCH] gen demo --- .../lib/src/rust/api/minimal.dart | 26 +++ .../lib/src/rust/frb_generated.dart | 204 +++++++++++++++++- .../lib/src/rust/frb_generated.io.dart | 106 +++++++++ .../lib/src/rust/frb_generated.web.dart | 96 ++++++++- .../dart_minimal/lib/src/rust/lib.dart | 10 + .../dart_minimal/rust/src/api/minimal.rs | 4 + .../dart_minimal/rust/src/frb_generated.rs | 175 ++++++++++++++- 7 files changed, 618 insertions(+), 3 deletions(-) create mode 100644 frb_example/dart_minimal/lib/src/rust/lib.dart diff --git a/frb_example/dart_minimal/lib/src/rust/api/minimal.dart b/frb_example/dart_minimal/lib/src/rust/api/minimal.dart index c6612f5d02..3dd3fbb093 100644 --- a/frb_example/dart_minimal/lib/src/rust/api/minimal.dart +++ b/frb_example/dart_minimal/lib/src/rust/api/minimal.dart @@ -4,7 +4,33 @@ // ignore_for_file: invalid_use_of_internal_member, unused_import, unnecessary_import import '../frb_generated.dart'; +import '../lib.dart'; import 'package:flutter_rust_bridge/flutter_rust_bridge_for_generated.dart'; +// These function are ignored because they are on traits that is not defined in current crate (put an empty `#[frb]` on it to unignore): `fmt` + Future minimalAdder({required int a, required int b}) => RustLib.instance.api.crateApiMinimalMinimalAdder(a: a, b: b); + +class StructWithRustAutoOpaqueFieldWithManyDerive { + final String content; + + const StructWithRustAutoOpaqueFieldWithManyDerive({ + required this.content, + }); + + Future f() => RustLib.instance.api + .crateApiMinimalStructWithRustAutoOpaqueFieldWithManyDeriveF( + that: this, + ); + + @override + int get hashCode => content.hashCode; + + @override + bool operator ==(Object other) => + identical(this, other) || + other is StructWithRustAutoOpaqueFieldWithManyDerive && + runtimeType == other.runtimeType && + content == other.content; +} diff --git a/frb_example/dart_minimal/lib/src/rust/frb_generated.dart b/frb_example/dart_minimal/lib/src/rust/frb_generated.dart index 3a6a9e9ac2..8959992651 100644 --- a/frb_example/dart_minimal/lib/src/rust/frb_generated.dart +++ b/frb_example/dart_minimal/lib/src/rust/frb_generated.dart @@ -9,6 +9,7 @@ import 'dart:convert'; import 'frb_generated.dart'; import 'frb_generated.io.dart' if (dart.library.js_interop) 'frb_generated.web.dart'; +import 'lib.dart'; import 'package:flutter_rust_bridge/flutter_rust_bridge_for_generated.dart'; /// Main entrypoint of the Rust API @@ -68,7 +69,7 @@ class RustLib extends BaseEntrypoint { String get codegenVersion => '2.3.0'; @override - int get rustContentHash => -2119384465; + int get rustContentHash => 1527444303; static const kDefaultExternalLibraryLoaderConfig = ExternalLibraryLoaderConfig( @@ -82,6 +83,15 @@ abstract class RustLibApi extends BaseApi { Future crateApiMinimalInitApp(); Future crateApiMinimalMinimalAdder({required int a, required int b}); + + Future crateApiMinimalStructWithRustAutoOpaqueFieldWithManyDeriveF( + {required StructWithRustAutoOpaqueFieldWithManyDerive that}); + + RustArcIncrementStrongCountFnType get rust_arc_increment_strong_count_String; + + RustArcDecrementStrongCountFnType get rust_arc_decrement_strong_count_String; + + CrossPlatformFinalizerArg get rust_arc_decrement_strong_count_StringPtr; } class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { @@ -141,49 +151,241 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { argNames: ["a", "b"], ); + @override + Future crateApiMinimalStructWithRustAutoOpaqueFieldWithManyDeriveF( + {required StructWithRustAutoOpaqueFieldWithManyDerive that}) { + return handler.executeNormal(NormalTask( + callFfi: (port_) { + final serializer = SseSerializer(generalizedFrbRustBinding); + sse_encode_box_autoadd_struct_with_rust_auto_opaque_field_with_many_derive( + that, serializer); + pdeCallFfi(generalizedFrbRustBinding, serializer, + funcId: 3, port: port_); + }, + codec: SseCodec( + decodeSuccessData: sse_decode_unit, + decodeErrorData: null, + ), + constMeta: + kCrateApiMinimalStructWithRustAutoOpaqueFieldWithManyDeriveFConstMeta, + argValues: [that], + apiImpl: this, + )); + } + + TaskConstMeta + get kCrateApiMinimalStructWithRustAutoOpaqueFieldWithManyDeriveFConstMeta => + const TaskConstMeta( + debugName: "struct_with_rust_auto_opaque_field_with_many_derive_f", + argNames: ["that"], + ); + + RustArcIncrementStrongCountFnType + get rust_arc_increment_strong_count_String => wire + .rust_arc_increment_strong_count_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerString; + + RustArcDecrementStrongCountFnType + get rust_arc_decrement_strong_count_String => wire + .rust_arc_decrement_strong_count_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerString; + + @protected + String + dco_decode_AutoExplicit_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerString( + dynamic raw) { + // Codec=Dco (DartCObject based), see doc to use other codecs + return dco_decode_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerString( + raw); + } + + @protected + String + dco_decode_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerString( + dynamic raw) { + // Codec=Dco (DartCObject based), see doc to use other codecs + return StringImpl.frbInternalDcoDecode(raw as List); + } + + @protected + StructWithRustAutoOpaqueFieldWithManyDerive + dco_decode_box_autoadd_struct_with_rust_auto_opaque_field_with_many_derive( + dynamic raw) { + // Codec=Dco (DartCObject based), see doc to use other codecs + return dco_decode_struct_with_rust_auto_opaque_field_with_many_derive(raw); + } + @protected int dco_decode_i_32(dynamic raw) { // Codec=Dco (DartCObject based), see doc to use other codecs return raw as int; } + @protected + StructWithRustAutoOpaqueFieldWithManyDerive + dco_decode_struct_with_rust_auto_opaque_field_with_many_derive( + dynamic raw) { + // Codec=Dco (DartCObject based), see doc to use other codecs + final arr = raw as List; + if (arr.length != 1) + throw Exception('unexpected arr length: expect 1 but see ${arr.length}'); + return StructWithRustAutoOpaqueFieldWithManyDerive( + content: + dco_decode_AutoExplicit_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerString( + arr[0]), + ); + } + @protected void dco_decode_unit(dynamic raw) { // Codec=Dco (DartCObject based), see doc to use other codecs return; } + @protected + BigInt dco_decode_usize(dynamic raw) { + // Codec=Dco (DartCObject based), see doc to use other codecs + return dcoDecodeU64(raw); + } + + @protected + String + sse_decode_AutoExplicit_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerString( + SseDeserializer deserializer) { + // Codec=Sse (Serialization based), see doc to use other codecs + var inner = + sse_decode_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerString( + deserializer); + return inner; + } + + @protected + String + sse_decode_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerString( + SseDeserializer deserializer) { + // Codec=Sse (Serialization based), see doc to use other codecs + return StringImpl.frbInternalSseDecode( + sse_decode_usize(deserializer), sse_decode_i_32(deserializer)); + } + + @protected + StructWithRustAutoOpaqueFieldWithManyDerive + sse_decode_box_autoadd_struct_with_rust_auto_opaque_field_with_many_derive( + SseDeserializer deserializer) { + // Codec=Sse (Serialization based), see doc to use other codecs + return (sse_decode_struct_with_rust_auto_opaque_field_with_many_derive( + deserializer)); + } + @protected int sse_decode_i_32(SseDeserializer deserializer) { // Codec=Sse (Serialization based), see doc to use other codecs return deserializer.buffer.getInt32(); } + @protected + StructWithRustAutoOpaqueFieldWithManyDerive + sse_decode_struct_with_rust_auto_opaque_field_with_many_derive( + SseDeserializer deserializer) { + // Codec=Sse (Serialization based), see doc to use other codecs + var var_content = + sse_decode_AutoExplicit_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerString( + deserializer); + return StructWithRustAutoOpaqueFieldWithManyDerive(content: var_content); + } + @protected void sse_decode_unit(SseDeserializer deserializer) { // Codec=Sse (Serialization based), see doc to use other codecs } + @protected + BigInt sse_decode_usize(SseDeserializer deserializer) { + // Codec=Sse (Serialization based), see doc to use other codecs + return deserializer.buffer.getBigUint64(); + } + @protected bool sse_decode_bool(SseDeserializer deserializer) { // Codec=Sse (Serialization based), see doc to use other codecs return deserializer.buffer.getUint8() != 0; } + @protected + void + sse_encode_AutoExplicit_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerString( + String self, SseSerializer serializer) { + // Codec=Sse (Serialization based), see doc to use other codecs + sse_encode_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerString( + self, serializer); + } + + @protected + void + sse_encode_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerString( + String self, SseSerializer serializer) { + // Codec=Sse (Serialization based), see doc to use other codecs + sse_encode_usize( + (self as StringImpl).frbInternalSseEncode(move: null), serializer); + } + + @protected + void + sse_encode_box_autoadd_struct_with_rust_auto_opaque_field_with_many_derive( + StructWithRustAutoOpaqueFieldWithManyDerive self, + SseSerializer serializer) { + // Codec=Sse (Serialization based), see doc to use other codecs + sse_encode_struct_with_rust_auto_opaque_field_with_many_derive( + self, serializer); + } + @protected void sse_encode_i_32(int self, SseSerializer serializer) { // Codec=Sse (Serialization based), see doc to use other codecs serializer.buffer.putInt32(self); } + @protected + void sse_encode_struct_with_rust_auto_opaque_field_with_many_derive( + StructWithRustAutoOpaqueFieldWithManyDerive self, + SseSerializer serializer) { + // Codec=Sse (Serialization based), see doc to use other codecs + sse_encode_AutoExplicit_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerString( + self.content, serializer); + } + @protected void sse_encode_unit(void self, SseSerializer serializer) { // Codec=Sse (Serialization based), see doc to use other codecs } + @protected + void sse_encode_usize(BigInt self, SseSerializer serializer) { + // Codec=Sse (Serialization based), see doc to use other codecs + serializer.buffer.putBigUint64(self); + } + @protected void sse_encode_bool(bool self, SseSerializer serializer) { // Codec=Sse (Serialization based), see doc to use other codecs serializer.buffer.putUint8(self ? 1 : 0); } } + +@sealed +class StringImpl extends RustOpaque implements String { + // Not to be used by end users + StringImpl.frbInternalDcoDecode(List wire) + : super.frbInternalDcoDecode(wire, _kStaticData); + + // Not to be used by end users + StringImpl.frbInternalSseDecode(BigInt ptr, int externalSizeOnNative) + : super.frbInternalSseDecode(ptr, externalSizeOnNative, _kStaticData); + + static final _kStaticData = RustArcStaticData( + rustArcIncrementStrongCount: + RustLib.instance.api.rust_arc_increment_strong_count_String, + rustArcDecrementStrongCount: + RustLib.instance.api.rust_arc_decrement_strong_count_String, + rustArcDecrementStrongCountPtr: + RustLib.instance.api.rust_arc_decrement_strong_count_StringPtr, + ); +} diff --git a/frb_example/dart_minimal/lib/src/rust/frb_generated.io.dart b/frb_example/dart_minimal/lib/src/rust/frb_generated.io.dart index 6937e24db3..7438ae4007 100644 --- a/frb_example/dart_minimal/lib/src/rust/frb_generated.io.dart +++ b/frb_example/dart_minimal/lib/src/rust/frb_generated.io.dart @@ -8,6 +8,7 @@ import 'dart:async'; import 'dart:convert'; import 'dart:ffi' as ffi; import 'frb_generated.dart'; +import 'lib.dart'; import 'package:flutter_rust_bridge/flutter_rust_bridge_for_generated_io.dart'; abstract class RustLibApiImplPlatform extends BaseApiImpl { @@ -18,27 +19,100 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl { required super.portManager, }); + CrossPlatformFinalizerArg get rust_arc_decrement_strong_count_StringPtr => wire + ._rust_arc_decrement_strong_count_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerStringPtr; + + @protected + String + dco_decode_AutoExplicit_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerString( + dynamic raw); + + @protected + String + dco_decode_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerString( + dynamic raw); + + @protected + StructWithRustAutoOpaqueFieldWithManyDerive + dco_decode_box_autoadd_struct_with_rust_auto_opaque_field_with_many_derive( + dynamic raw); + @protected int dco_decode_i_32(dynamic raw); + @protected + StructWithRustAutoOpaqueFieldWithManyDerive + dco_decode_struct_with_rust_auto_opaque_field_with_many_derive( + dynamic raw); + @protected void dco_decode_unit(dynamic raw); + @protected + BigInt dco_decode_usize(dynamic raw); + + @protected + String + sse_decode_AutoExplicit_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerString( + SseDeserializer deserializer); + + @protected + String + sse_decode_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerString( + SseDeserializer deserializer); + + @protected + StructWithRustAutoOpaqueFieldWithManyDerive + sse_decode_box_autoadd_struct_with_rust_auto_opaque_field_with_many_derive( + SseDeserializer deserializer); + @protected int sse_decode_i_32(SseDeserializer deserializer); + @protected + StructWithRustAutoOpaqueFieldWithManyDerive + sse_decode_struct_with_rust_auto_opaque_field_with_many_derive( + SseDeserializer deserializer); + @protected void sse_decode_unit(SseDeserializer deserializer); + @protected + BigInt sse_decode_usize(SseDeserializer deserializer); + @protected bool sse_decode_bool(SseDeserializer deserializer); + @protected + void + sse_encode_AutoExplicit_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerString( + String self, SseSerializer serializer); + + @protected + void + sse_encode_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerString( + String self, SseSerializer serializer); + + @protected + void + sse_encode_box_autoadd_struct_with_rust_auto_opaque_field_with_many_derive( + StructWithRustAutoOpaqueFieldWithManyDerive self, + SseSerializer serializer); + @protected void sse_encode_i_32(int self, SseSerializer serializer); + @protected + void sse_encode_struct_with_rust_auto_opaque_field_with_many_derive( + StructWithRustAutoOpaqueFieldWithManyDerive self, + SseSerializer serializer); + @protected void sse_encode_unit(void self, SseSerializer serializer); + @protected + void sse_encode_usize(BigInt self, SseSerializer serializer); + @protected void sse_encode_bool(bool self, SseSerializer serializer); } @@ -56,4 +130,36 @@ class RustLibWire implements BaseWire { /// The symbols are looked up in [dynamicLibrary]. RustLibWire(ffi.DynamicLibrary dynamicLibrary) : _lookup = dynamicLibrary.lookup; + + void + rust_arc_increment_strong_count_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerString( + ffi.Pointer ptr, + ) { + return _rust_arc_increment_strong_count_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerString( + ptr, + ); + } + + late final _rust_arc_increment_strong_count_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerStringPtr = + _lookup)>>( + 'frbgen_frb_example_dart_minimal_rust_arc_increment_strong_count_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerString'); + late final _rust_arc_increment_strong_count_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerString = + _rust_arc_increment_strong_count_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerStringPtr + .asFunction)>(); + + void + rust_arc_decrement_strong_count_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerString( + ffi.Pointer ptr, + ) { + return _rust_arc_decrement_strong_count_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerString( + ptr, + ); + } + + late final _rust_arc_decrement_strong_count_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerStringPtr = + _lookup)>>( + 'frbgen_frb_example_dart_minimal_rust_arc_decrement_strong_count_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerString'); + late final _rust_arc_decrement_strong_count_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerString = + _rust_arc_decrement_strong_count_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerStringPtr + .asFunction)>(); } diff --git a/frb_example/dart_minimal/lib/src/rust/frb_generated.web.dart b/frb_example/dart_minimal/lib/src/rust/frb_generated.web.dart index cfa8d8f979..1b74fe6ee5 100644 --- a/frb_example/dart_minimal/lib/src/rust/frb_generated.web.dart +++ b/frb_example/dart_minimal/lib/src/rust/frb_generated.web.dart @@ -10,6 +10,7 @@ import 'api/minimal.dart'; import 'dart:async'; import 'dart:convert'; import 'frb_generated.dart'; +import 'lib.dart'; import 'package:flutter_rust_bridge/flutter_rust_bridge_for_generated_web.dart'; abstract class RustLibApiImplPlatform extends BaseApiImpl { @@ -20,27 +21,100 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl { required super.portManager, }); + CrossPlatformFinalizerArg get rust_arc_decrement_strong_count_StringPtr => wire + .rust_arc_decrement_strong_count_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerString; + + @protected + String + dco_decode_AutoExplicit_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerString( + dynamic raw); + + @protected + String + dco_decode_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerString( + dynamic raw); + + @protected + StructWithRustAutoOpaqueFieldWithManyDerive + dco_decode_box_autoadd_struct_with_rust_auto_opaque_field_with_many_derive( + dynamic raw); + @protected int dco_decode_i_32(dynamic raw); + @protected + StructWithRustAutoOpaqueFieldWithManyDerive + dco_decode_struct_with_rust_auto_opaque_field_with_many_derive( + dynamic raw); + @protected void dco_decode_unit(dynamic raw); + @protected + BigInt dco_decode_usize(dynamic raw); + + @protected + String + sse_decode_AutoExplicit_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerString( + SseDeserializer deserializer); + + @protected + String + sse_decode_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerString( + SseDeserializer deserializer); + + @protected + StructWithRustAutoOpaqueFieldWithManyDerive + sse_decode_box_autoadd_struct_with_rust_auto_opaque_field_with_many_derive( + SseDeserializer deserializer); + @protected int sse_decode_i_32(SseDeserializer deserializer); + @protected + StructWithRustAutoOpaqueFieldWithManyDerive + sse_decode_struct_with_rust_auto_opaque_field_with_many_derive( + SseDeserializer deserializer); + @protected void sse_decode_unit(SseDeserializer deserializer); + @protected + BigInt sse_decode_usize(SseDeserializer deserializer); + @protected bool sse_decode_bool(SseDeserializer deserializer); + @protected + void + sse_encode_AutoExplicit_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerString( + String self, SseSerializer serializer); + + @protected + void + sse_encode_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerString( + String self, SseSerializer serializer); + + @protected + void + sse_encode_box_autoadd_struct_with_rust_auto_opaque_field_with_many_derive( + StructWithRustAutoOpaqueFieldWithManyDerive self, + SseSerializer serializer); + @protected void sse_encode_i_32(int self, SseSerializer serializer); + @protected + void sse_encode_struct_with_rust_auto_opaque_field_with_many_derive( + StructWithRustAutoOpaqueFieldWithManyDerive self, + SseSerializer serializer); + @protected void sse_encode_unit(void self, SseSerializer serializer); + @protected + void sse_encode_usize(BigInt self, SseSerializer serializer); + @protected void sse_encode_bool(bool self, SseSerializer serializer); } @@ -49,6 +123,18 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl { class RustLibWire implements BaseWire { RustLibWire.fromExternalLibrary(ExternalLibrary lib); + + void rust_arc_increment_strong_count_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerString( + int ptr) => + wasmModule + .rust_arc_increment_strong_count_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerString( + ptr); + + void rust_arc_decrement_strong_count_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerString( + int ptr) => + wasmModule + .rust_arc_decrement_strong_count_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerString( + ptr); } @JS('wasm_bindgen') @@ -56,4 +142,12 @@ external RustLibWasmModule get wasmModule; @JS() @anonymous -extension type RustLibWasmModule._(JSObject _) implements JSObject {} +extension type RustLibWasmModule._(JSObject _) implements JSObject { + external void + rust_arc_increment_strong_count_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerString( + int ptr); + + external void + rust_arc_decrement_strong_count_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerString( + int ptr); +} diff --git a/frb_example/dart_minimal/lib/src/rust/lib.dart b/frb_example/dart_minimal/lib/src/rust/lib.dart new file mode 100644 index 0000000000..06ce63e0d2 --- /dev/null +++ b/frb_example/dart_minimal/lib/src/rust/lib.dart @@ -0,0 +1,10 @@ +// This file is automatically generated, so please do not edit it. +// @generated by `flutter_rust_bridge`@ 2.3.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'; + +// Rust type: RustOpaqueMoi> +abstract class String implements RustOpaqueInterface {} diff --git a/frb_example/dart_minimal/rust/src/api/minimal.rs b/frb_example/dart_minimal/rust/src/api/minimal.rs index 91f50e0026..80792ae1d8 100644 --- a/frb_example/dart_minimal/rust/src/api/minimal.rs +++ b/frb_example/dart_minimal/rust/src/api/minimal.rs @@ -15,3 +15,7 @@ pub fn minimal_adder(a: i32, b: i32) -> i32 { pub struct StructWithRustAutoOpaqueFieldWithManyDerive { content: crate::frb_generated::RustAutoOpaque, } + +impl StructWithRustAutoOpaqueFieldWithManyDerive { + pub fn f(&self) {} +} diff --git a/frb_example/dart_minimal/rust/src/frb_generated.rs b/frb_example/dart_minimal/rust/src/frb_generated.rs index 8c875580c2..725384cd8b 100644 --- a/frb_example/dart_minimal/rust/src/frb_generated.rs +++ b/frb_example/dart_minimal/rust/src/frb_generated.rs @@ -25,6 +25,7 @@ // Section: imports +use crate::*; use flutter_rust_bridge::for_generated::byteorder::{NativeEndian, ReadBytesExt, WriteBytesExt}; use flutter_rust_bridge::for_generated::{transform_result_dco, Lifetimeable, Lockable}; use flutter_rust_bridge::{Handler, IntoIntoDart}; @@ -37,7 +38,7 @@ flutter_rust_bridge::frb_generated_boilerplate!( default_rust_auto_opaque = RustAutoOpaqueMoi, ); pub(crate) const FLUTTER_RUST_BRIDGE_CODEGEN_VERSION: &str = "2.3.0"; -pub(crate) const FLUTTER_RUST_BRIDGE_CODEGEN_CONTENT_HASH: i32 = -2119384465; +pub(crate) const FLUTTER_RUST_BRIDGE_CODEGEN_CONTENT_HASH: i32 = 1527444303; // Section: executor @@ -114,9 +115,73 @@ fn wire__crate__api__minimal__minimal_adder_impl( }, ) } +fn wire__crate__api__minimal__struct_with_rust_auto_opaque_field_with_many_derive_f_impl( + port_: flutter_rust_bridge::for_generated::MessagePort, + ptr_: flutter_rust_bridge::for_generated::PlatformGeneralizedUint8ListPtr, + rust_vec_len_: i32, + data_len_: i32, +) { + FLUTTER_RUST_BRIDGE_HANDLER.wrap_normal::( + flutter_rust_bridge::for_generated::TaskInfo { + debug_name: "struct_with_rust_auto_opaque_field_with_many_derive_f", + port: Some(port_), + mode: flutter_rust_bridge::for_generated::FfiCallMode::Normal, + }, + move || { + let message = unsafe { + flutter_rust_bridge::for_generated::Dart2RustMessageSse::from_wire( + ptr_, + rust_vec_len_, + data_len_, + ) + }; + let mut deserializer = + flutter_rust_bridge::for_generated::SseDeserializer::new(message); + let api_that = + ::sse_decode( + &mut deserializer, + ); + deserializer.end(); + move |context| { + transform_result_sse::<_, ()>((move || { + let output_ok = Result::<_, ()>::Ok({ + crate::api::minimal::StructWithRustAutoOpaqueFieldWithManyDerive::f( + &api_that, + ); + })?; + Ok(output_ok) + })()) + } + }, + ) +} + +// Section: related_funcs + +flutter_rust_bridge::frb_generated_moi_arc_impl_value!( + flutter_rust_bridge::for_generated::RustAutoOpaqueInner +); // Section: dart2rust +impl SseDecode for RustAutoOpaqueMoi { + // Codec=Sse (Serialization based), see doc to use other codecs + fn sse_decode(deserializer: &mut flutter_rust_bridge::for_generated::SseDeserializer) -> Self { + let mut inner = , + >>::sse_decode(deserializer); + return flutter_rust_bridge::for_generated::rust_auto_opaque_explicit_decode(inner); + } +} + +impl SseDecode for RustOpaqueMoi> { + // Codec=Sse (Serialization based), see doc to use other codecs + fn sse_decode(deserializer: &mut flutter_rust_bridge::for_generated::SseDeserializer) -> Self { + let mut inner = ::sse_decode(deserializer); + return decode_rust_opaque_moi(inner); + } +} + impl SseDecode for i32 { // Codec=Sse (Serialization based), see doc to use other codecs fn sse_decode(deserializer: &mut flutter_rust_bridge::for_generated::SseDeserializer) -> Self { @@ -124,11 +189,28 @@ impl SseDecode for i32 { } } +impl SseDecode for crate::api::minimal::StructWithRustAutoOpaqueFieldWithManyDerive { + // Codec=Sse (Serialization based), see doc to use other codecs + fn sse_decode(deserializer: &mut flutter_rust_bridge::for_generated::SseDeserializer) -> Self { + let mut var_content = >::sse_decode(deserializer); + return crate::api::minimal::StructWithRustAutoOpaqueFieldWithManyDerive { + content: var_content, + }; + } +} + impl SseDecode for () { // Codec=Sse (Serialization based), see doc to use other codecs fn sse_decode(deserializer: &mut flutter_rust_bridge::for_generated::SseDeserializer) -> Self {} } +impl SseDecode for usize { + // Codec=Sse (Serialization based), see doc to use other codecs + fn sse_decode(deserializer: &mut flutter_rust_bridge::for_generated::SseDeserializer) -> Self { + deserializer.cursor.read_u64::().unwrap() as _ + } +} + impl SseDecode for bool { // Codec=Sse (Serialization based), see doc to use other codecs fn sse_decode(deserializer: &mut flutter_rust_bridge::for_generated::SseDeserializer) -> Self { @@ -147,6 +229,12 @@ fn pde_ffi_dispatcher_primary_impl( match func_id { 1 => wire__crate__api__minimal__init_app_impl(port, ptr, rust_vec_len, data_len), 2 => wire__crate__api__minimal__minimal_adder_impl(port, ptr, rust_vec_len, data_len), + 3 => wire__crate__api__minimal__struct_with_rust_auto_opaque_field_with_many_derive_f_impl( + port, + ptr, + rust_vec_len, + data_len, + ), _ => unreachable!(), } } @@ -165,6 +253,44 @@ fn pde_ffi_dispatcher_sync_impl( // Section: rust2dart +// Codec=Dco (DartCObject based), see doc to use other codecs +impl flutter_rust_bridge::IntoDart + for crate::api::minimal::StructWithRustAutoOpaqueFieldWithManyDerive +{ + fn into_dart(self) -> flutter_rust_bridge::for_generated::DartAbi { + [self.content.into_into_dart().into_dart()].into_dart() + } +} +impl flutter_rust_bridge::for_generated::IntoDartExceptPrimitive + for crate::api::minimal::StructWithRustAutoOpaqueFieldWithManyDerive +{ +} +impl + flutter_rust_bridge::IntoIntoDart< + crate::api::minimal::StructWithRustAutoOpaqueFieldWithManyDerive, + > for crate::api::minimal::StructWithRustAutoOpaqueFieldWithManyDerive +{ + fn into_into_dart(self) -> crate::api::minimal::StructWithRustAutoOpaqueFieldWithManyDerive { + self + } +} + +impl SseEncode for RustAutoOpaqueMoi { + // Codec=Sse (Serialization based), see doc to use other codecs + fn sse_encode(self, serializer: &mut flutter_rust_bridge::for_generated::SseSerializer) { + >>::sse_encode(flutter_rust_bridge::for_generated::rust_auto_opaque_explicit_encode(self), serializer); + } +} + +impl SseEncode for RustOpaqueMoi> { + // Codec=Sse (Serialization based), see doc to use other codecs + fn sse_encode(self, serializer: &mut flutter_rust_bridge::for_generated::SseSerializer) { + let (ptr, size) = self.sse_encode_raw(); + ::sse_encode(ptr, serializer); + ::sse_encode(size, serializer); + } +} + impl SseEncode for i32 { // Codec=Sse (Serialization based), see doc to use other codecs fn sse_encode(self, serializer: &mut flutter_rust_bridge::for_generated::SseSerializer) { @@ -172,11 +298,28 @@ impl SseEncode for i32 { } } +impl SseEncode for crate::api::minimal::StructWithRustAutoOpaqueFieldWithManyDerive { + // Codec=Sse (Serialization based), see doc to use other codecs + fn sse_encode(self, serializer: &mut flutter_rust_bridge::for_generated::SseSerializer) { + >::sse_encode(self.content, serializer); + } +} + impl SseEncode for () { // Codec=Sse (Serialization based), see doc to use other codecs fn sse_encode(self, serializer: &mut flutter_rust_bridge::for_generated::SseSerializer) {} } +impl SseEncode for usize { + // Codec=Sse (Serialization based), see doc to use other codecs + fn sse_encode(self, serializer: &mut flutter_rust_bridge::for_generated::SseSerializer) { + serializer + .cursor + .write_u64::(self as _) + .unwrap(); + } +} + impl SseEncode for bool { // Codec=Sse (Serialization based), see doc to use other codecs fn sse_encode(self, serializer: &mut flutter_rust_bridge::for_generated::SseSerializer) { @@ -192,6 +335,7 @@ mod io { // Section: imports use super::*; + use crate::*; use flutter_rust_bridge::for_generated::byteorder::{ NativeEndian, ReadBytesExt, WriteBytesExt, }; @@ -201,6 +345,20 @@ mod io { // Section: boilerplate flutter_rust_bridge::frb_generated_boilerplate_io!(); + + #[no_mangle] + pub extern "C" fn frbgen_frb_example_dart_minimal_rust_arc_increment_strong_count_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerString( + ptr: *const std::ffi::c_void, + ) { + MoiArc::>::increment_strong_count(ptr as _); + } + + #[no_mangle] + pub extern "C" fn frbgen_frb_example_dart_minimal_rust_arc_decrement_strong_count_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerString( + ptr: *const std::ffi::c_void, + ) { + MoiArc::>::decrement_strong_count(ptr as _); + } } #[cfg(not(target_family = "wasm"))] pub use io::*; @@ -214,6 +372,7 @@ mod web { // Section: imports use super::*; + use crate::*; use flutter_rust_bridge::for_generated::byteorder::{ NativeEndian, ReadBytesExt, WriteBytesExt, }; @@ -225,6 +384,20 @@ mod web { // Section: boilerplate flutter_rust_bridge::frb_generated_boilerplate_web!(); + + #[wasm_bindgen] + pub fn rust_arc_increment_strong_count_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerString( + ptr: *const std::ffi::c_void, + ) { + MoiArc::>::increment_strong_count(ptr as _); + } + + #[wasm_bindgen] + pub fn rust_arc_decrement_strong_count_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerString( + ptr: *const std::ffi::c_void, + ) { + MoiArc::>::decrement_strong_count(ptr as _); + } } #[cfg(target_family = "wasm")] pub use web::*;