Skip to content

Commit

Permalink
gen demo
Browse files Browse the repository at this point in the history
  • Loading branch information
fzyzcjy committed Sep 12, 2024
1 parent ec7c9cd commit b82a490
Show file tree
Hide file tree
Showing 7 changed files with 618 additions and 3 deletions.
26 changes: 26 additions & 0 deletions frb_example/dart_minimal/lib/src/rust/api/minimal.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<int> 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<void> 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;
}
204 changes: 203 additions & 1 deletion frb_example/dart_minimal/lib/src/rust/frb_generated.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -68,7 +69,7 @@ class RustLib extends BaseEntrypoint<RustLibApi, RustLibApiImpl, RustLibWire> {
String get codegenVersion => '2.3.0';

@override
int get rustContentHash => -2119384465;
int get rustContentHash => 1527444303;

static const kDefaultExternalLibraryLoaderConfig =
ExternalLibraryLoaderConfig(
Expand All @@ -82,6 +83,15 @@ abstract class RustLibApi extends BaseApi {
Future<void> crateApiMinimalInitApp();

Future<int> crateApiMinimalMinimalAdder({required int a, required int b});

Future<void> 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 {
Expand Down Expand Up @@ -141,49 +151,241 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
argNames: ["a", "b"],
);

@override
Future<void> 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<dynamic>);
}

@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<dynamic>;
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<dynamic> 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,
);
}
Loading

0 comments on commit b82a490

Please sign in to comment.