diff --git a/example/pubspec.lock b/example/pubspec.lock index 608b821..e285b47 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -1,6 +1,20 @@ # Generated by pub # See https://dart.dev/tools/pub/glossary#lockfile packages: + archive: + dependency: transitive + description: + name: archive + url: "https://pub.dartlang.org" + source: hosted + version: "3.3.5" + args: + dependency: transitive + description: + name: args + url: "https://pub.dartlang.org" + source: hosted + version: "2.3.1" async: dependency: transitive description: @@ -15,6 +29,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "2.1.0" + build_cli_annotations: + dependency: transitive + description: + name: build_cli_annotations + url: "https://pub.dartlang.org" + source: hosted + version: "2.1.0" characters: dependency: transitive description: @@ -36,6 +57,27 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.16.0" + colorize: + dependency: transitive + description: + name: colorize + url: "https://pub.dartlang.org" + source: hosted + version: "3.0.0" + convert: + dependency: transitive + description: + name: convert + url: "https://pub.dartlang.org" + source: hosted + version: "3.1.1" + crypto: + dependency: transitive + description: + name: crypto + url: "https://pub.dartlang.org" + source: hosted + version: "3.0.2" cupertino_icons: dependency: "direct main" description: @@ -75,7 +117,7 @@ packages: name: flutter_rust_bridge url: "https://pub.dartlang.org" source: hosted - version: "1.41.3" + version: "1.59.0" flutter_test: dependency: "direct dev" description: flutter @@ -86,6 +128,20 @@ packages: description: flutter source: sdk version: "0.0.0" + http: + dependency: transitive + description: + name: http + url: "https://pub.dartlang.org" + source: hosted + version: "0.13.5" + http_parser: + dependency: transitive + description: + name: http_parser + url: "https://pub.dartlang.org" + source: hosted + version: "4.0.2" js: dependency: transitive description: @@ -100,6 +156,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "2.0.0" + logging: + dependency: transitive + description: + name: logging + url: "https://pub.dartlang.org" + source: hosted + version: "1.1.0" matcher: dependency: transitive description: @@ -128,6 +191,13 @@ packages: relative: true source: path version: "0.3.1" + mime: + dependency: transitive + description: + name: mime + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.3" path: dependency: transitive description: @@ -170,6 +240,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "0.1.0" + petitparser: + dependency: transitive + description: + name: petitparser + url: "https://pub.dartlang.org" + source: hosted + version: "5.1.0" plugin_platform_interface: dependency: transitive description: @@ -177,6 +254,48 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "2.1.2" + pointycastle: + dependency: transitive + description: + name: pointycastle + url: "https://pub.dartlang.org" + source: hosted + version: "3.6.2" + pool: + dependency: transitive + description: + name: pool + url: "https://pub.dartlang.org" + source: hosted + version: "1.5.1" + puppeteer: + dependency: transitive + description: + name: puppeteer + url: "https://pub.dartlang.org" + source: hosted + version: "2.20.0" + shelf: + dependency: transitive + description: + name: shelf + url: "https://pub.dartlang.org" + source: hosted + version: "1.4.0" + shelf_static: + dependency: transitive + description: + name: shelf_static + url: "https://pub.dartlang.org" + source: hosted + version: "1.1.1" + shelf_web_socket: + dependency: transitive + description: + name: shelf_web_socket + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.3" sky_engine: dependency: transitive description: flutter @@ -224,6 +343,27 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "0.4.12" + tuple: + dependency: transitive + description: + name: tuple + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.1" + typed_data: + dependency: transitive + description: + name: typed_data + url: "https://pub.dartlang.org" + source: hosted + version: "1.3.1" + uuid: + dependency: transitive + description: + name: uuid + url: "https://pub.dartlang.org" + source: hosted + version: "3.0.7" vector_math: dependency: transitive description: @@ -231,6 +371,20 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "2.1.2" + web_socket_channel: + dependency: transitive + description: + name: web_socket_channel + url: "https://pub.dartlang.org" + source: hosted + version: "2.2.0" + yaml: + dependency: transitive + description: + name: yaml + url: "https://pub.dartlang.org" + source: hosted + version: "3.1.1" sdks: dart: ">=2.18.0 <3.0.0" flutter: ">=2.8.0" diff --git a/frameworks/rust_crate/rust_crate/bridge_generated.h b/frameworks/rust_crate/rust_crate/bridge_generated.h index a9e76b8..6920800 100644 --- a/frameworks/rust_crate/rust_crate/bridge_generated.h +++ b/frameworks/rust_crate/rust_crate/bridge_generated.h @@ -1,6 +1,13 @@ #include #include #include +typedef struct _Dart_Handle* Dart_Handle; + +typedef struct DartCObject DartCObject; + +typedef int64_t DartPort; + +typedef bool (*DartPostCObjectFnType)(DartPort port_id, void *message); typedef struct wire_uint_8_list { uint8_t *ptr; @@ -28,15 +35,17 @@ typedef struct wire_Metadata { uint64_t *file_size; } wire_Metadata; -typedef struct WireSyncReturnStruct { - uint8_t *ptr; - int32_t len; - bool success; -} WireSyncReturnStruct; +typedef struct DartCObject *WireSyncReturn; -typedef int64_t DartPort; +void store_dart_post_cobject(DartPostCObjectFnType ptr); -typedef bool (*DartPostCObjectFnType)(DartPort port_id, void *message); +Dart_Handle get_dart_object(uintptr_t ptr); + +void drop_dart_object(uintptr_t ptr); + +uintptr_t new_dart_opaque(Dart_Handle handle); + +intptr_t init_frb_dart_api_dl(void *obj); void wire_ping(int64_t port_); @@ -60,9 +69,7 @@ uint64_t *new_box_autoadd_u64_0(uint64_t value); struct wire_uint_8_list *new_uint_8_list_0(int32_t len); -void free_WireSyncReturnStruct(struct WireSyncReturnStruct val); - -void store_dart_post_cobject(DartPostCObjectFnType ptr); +void free_WireSyncReturn(WireSyncReturn ptr); static int64_t dummy_method_to_enforce_bundling(void) { int64_t dummy_var = 0; @@ -76,7 +83,10 @@ static int64_t dummy_method_to_enforce_bundling(void) { dummy_var ^= ((int64_t) (void*) new_box_autoadd_u16_0); dummy_var ^= ((int64_t) (void*) new_box_autoadd_u64_0); dummy_var ^= ((int64_t) (void*) new_uint_8_list_0); - dummy_var ^= ((int64_t) (void*) free_WireSyncReturnStruct); + dummy_var ^= ((int64_t) (void*) free_WireSyncReturn); dummy_var ^= ((int64_t) (void*) store_dart_post_cobject); + dummy_var ^= ((int64_t) (void*) get_dart_object); + dummy_var ^= ((int64_t) (void*) drop_dart_object); + dummy_var ^= ((int64_t) (void*) new_dart_opaque); return dummy_var; -} +} \ No newline at end of file diff --git a/justfile b/justfile index 8348ff0..1ae9ee1 100644 --- a/justfile +++ b/justfile @@ -7,13 +7,13 @@ gen: --c-output "$REPO_DIR/frameworks/rust_crate/rust_crate/bridge_generated.h" build-linux: - export REPO_DIR="$PWD"; cd "$PWD/rust"; cargo build --release; cp "$REPO_DIR/rust/target/release/librust.a" "$REPO_DIR/linux/rust" + export REPO_DIR="$PWD"; cd "$PWD/rust"; cargo build --release; cp "$REPO_DIR/rust/target/release/librust.so" "$REPO_DIR/linux/rust" build-windows: - export REPO_DIR="$PWD"; cd "$PWD/rust"; cargo build --release; cp "$REPO_DIR/rust/target/release/rust.dll" "$REPO_DIR/rust/target/release/rust.lib" "$REPO_DIR/windows/rust" + export REPO_DIR="$PWD"; cd "$PWD/rust"; cargo build --release; cp "$REPO_DIR/rust/target/release/rust.dll" "$REPO_DIR/windows/rust" build-macos: - export REPO_DIR="$PWD"; cd "$PWD/rust"; cargo build --release; cp "$REPO_DIR/rust/target/release/librust.a" "$REPO_DIR/macos/Libs" + export REPO_DIR="$PWD"; cd "$PWD/rust"; cargo build --release; cp "$REPO_DIR/rust/target/release/librust.dylib" "$REPO_DIR/macos/Libs" build-android: cd rust; cargo ndk -t armeabi-v7a -t arm64-v8a -t x86_64 -t x86 -o ../android/src/main/jniLibs build --release diff --git a/lib/src/bridge_generated.dart b/lib/src/bridge_generated.dart index 27e7b44..1db2b22 100644 --- a/lib/src/bridge_generated.dart +++ b/lib/src/bridge_generated.dart @@ -1,11 +1,13 @@ // AUTO GENERATED FILE, DO NOT EDIT. -// Generated by `flutter_rust_bridge`. - -// ignore_for_file: non_constant_identifier_names, unused_element, duplicate_ignore, directives_ordering, curly_braces_in_flow_control_structures, unnecessary_lambdas, slash_for_doc_comments, prefer_const_literals_to_create_immutables, implicit_dynamic_list_literal, duplicate_import, unused_import, prefer_single_quotes, prefer_const_constructors, use_super_parameters, always_use_package_imports +// Generated by `flutter_rust_bridge`@ 1.59.0. +// ignore_for_file: non_constant_identifier_names, unused_element, duplicate_ignore, directives_ordering, curly_braces_in_flow_control_structures, unnecessary_lambdas, slash_for_doc_comments, prefer_const_literals_to_create_immutables, implicit_dynamic_list_literal, duplicate_import, unused_import, prefer_single_quotes, prefer_const_constructors, use_super_parameters, always_use_package_imports, annotate_overrides, invalid_use_of_protected_member, constant_identifier_names, invalid_use_of_internal_member import 'dart:convert'; -import 'dart:typed_data'; +import 'dart:async'; import 'package:flutter_rust_bridge/flutter_rust_bridge.dart'; + +import 'package:meta/meta.dart'; +import 'package:meta/meta.dart'; import 'dart:ffi' as ffi; abstract class Rust { @@ -68,18 +70,23 @@ class Metadata { }); } -class RustImpl extends FlutterRustBridgeBase implements Rust { - factory RustImpl(ffi.DynamicLibrary dylib) => RustImpl.raw(RustWire(dylib)); - - RustImpl.raw(RustWire inner) : super(inner); +class RustImpl implements Rust { + final RustPlatform _platform; + factory RustImpl(ExternalLibrary dylib) => RustImpl.raw(RustPlatform(dylib)); - Future ping({dynamic hint}) => executeNormal(FlutterRustBridgeTask( - callFfi: (port_) => inner.wire_ping(port_), - parseSuccessData: _wire2api_String, - constMeta: kPingConstMeta, - argValues: [], - hint: hint, - )); + /// Only valid on web/WASM platforms. + factory RustImpl.wasm(FutureOr module) => + RustImpl(module as ExternalLibrary); + RustImpl.raw(this._platform); + Future ping({dynamic hint}) { + return _platform.executeNormal(FlutterRustBridgeTask( + callFfi: (port_) => _platform.inner.wire_ping(port_), + parseSuccessData: _wire2api_String, + constMeta: kPingConstMeta, + argValues: [], + hint: hint, + )); + } FlutterRustBridgeTaskConstMeta get kPingConstMeta => const FlutterRustBridgeTaskConstMeta( @@ -87,15 +94,16 @@ class RustImpl extends FlutterRustBridgeBase implements Rust { argNames: [], ); - Future readMetadata({required String file, dynamic hint}) => - executeNormal(FlutterRustBridgeTask( - callFfi: (port_) => - inner.wire_read_metadata(port_, _api2wire_String(file)), - parseSuccessData: _wire2api_metadata, - constMeta: kReadMetadataConstMeta, - argValues: [file], - hint: hint, - )); + Future readMetadata({required String file, dynamic hint}) { + var arg0 = _platform.api2wire_String(file); + return _platform.executeNormal(FlutterRustBridgeTask( + callFfi: (port_) => _platform.inner.wire_read_metadata(port_, arg0), + parseSuccessData: _wire2api_metadata, + constMeta: kReadMetadataConstMeta, + argValues: [file], + hint: hint, + )); + } FlutterRustBridgeTaskConstMeta get kReadMetadataConstMeta => const FlutterRustBridgeTaskConstMeta( @@ -104,15 +112,18 @@ class RustImpl extends FlutterRustBridgeBase implements Rust { ); Future writeMetadata( - {required String file, required Metadata metadata, dynamic hint}) => - executeNormal(FlutterRustBridgeTask( - callFfi: (port_) => inner.wire_write_metadata(port_, - _api2wire_String(file), _api2wire_box_autoadd_metadata(metadata)), - parseSuccessData: _wire2api_unit, - constMeta: kWriteMetadataConstMeta, - argValues: [file, metadata], - hint: hint, - )); + {required String file, required Metadata metadata, dynamic hint}) { + var arg0 = _platform.api2wire_String(file); + var arg1 = _platform.api2wire_box_autoadd_metadata(metadata); + return _platform.executeNormal(FlutterRustBridgeTask( + callFfi: (port_) => + _platform.inner.wire_write_metadata(port_, arg0, arg1), + parseSuccessData: _wire2api_unit, + constMeta: kWriteMetadataConstMeta, + argValues: [file, metadata], + hint: hint, + )); + } FlutterRustBridgeTaskConstMeta get kWriteMetadataConstMeta => const FlutterRustBridgeTaskConstMeta( @@ -120,234 +131,267 @@ class RustImpl extends FlutterRustBridgeBase implements Rust { argNames: ["file", "metadata"], ); - // Section: api2wire - ffi.Pointer _api2wire_String(String raw) { - return _api2wire_uint_8_list(utf8.encoder.convert(raw)); + void dispose() { + _platform.dispose(); } +// Section: wire2api - ffi.Pointer _api2wire_box_autoadd_f64(double raw) { - return inner.new_box_autoadd_f64_0(_api2wire_f64(raw)); + String _wire2api_String(dynamic raw) { + return raw as String; } - ffi.Pointer _api2wire_box_autoadd_i32(int raw) { - return inner.new_box_autoadd_i32_0(_api2wire_i32(raw)); + double _wire2api_box_autoadd_f64(dynamic raw) { + return raw as double; } - ffi.Pointer _api2wire_box_autoadd_image(Image raw) { - final ptr = inner.new_box_autoadd_image_0(); - _api_fill_to_wire_image(raw, ptr.ref); - return ptr; + int _wire2api_box_autoadd_i32(dynamic raw) { + return raw as int; } - ffi.Pointer _api2wire_box_autoadd_metadata(Metadata raw) { - final ptr = inner.new_box_autoadd_metadata_0(); - _api_fill_to_wire_metadata(raw, ptr.ref); - return ptr; + Image _wire2api_box_autoadd_image(dynamic raw) { + return _wire2api_image(raw); } - ffi.Pointer _api2wire_box_autoadd_u16(int raw) { - return inner.new_box_autoadd_u16_0(_api2wire_u16(raw)); + int _wire2api_box_autoadd_u16(dynamic raw) { + return raw as int; } - ffi.Pointer _api2wire_box_autoadd_u64(int raw) { - return inner.new_box_autoadd_u64_0(_api2wire_u64(raw)); + int _wire2api_box_autoadd_u64(dynamic raw) { + return _wire2api_u64(raw); } - double _api2wire_f64(double raw) { - return raw; + double _wire2api_f64(dynamic raw) { + return raw as double; } - int _api2wire_i32(int raw) { - return raw; + int _wire2api_i32(dynamic raw) { + return raw as int; } - ffi.Pointer _api2wire_opt_String(String? raw) { - return raw == null ? ffi.nullptr : _api2wire_String(raw); + Image _wire2api_image(dynamic raw) { + final arr = raw as List; + if (arr.length != 2) + throw Exception('unexpected arr length: expect 2 but see ${arr.length}'); + return Image( + mimeType: _wire2api_String(arr[0]), + data: _wire2api_uint_8_list(arr[1]), + ); } - ffi.Pointer _api2wire_opt_box_autoadd_f64(double? raw) { - return raw == null ? ffi.nullptr : _api2wire_box_autoadd_f64(raw); + Metadata _wire2api_metadata(dynamic raw) { + final arr = raw as List; + if (arr.length != 13) + throw Exception('unexpected arr length: expect 13 but see ${arr.length}'); + return Metadata( + title: _wire2api_opt_String(arr[0]), + durationMs: _wire2api_opt_box_autoadd_f64(arr[1]), + artist: _wire2api_opt_String(arr[2]), + album: _wire2api_opt_String(arr[3]), + albumArtist: _wire2api_opt_String(arr[4]), + trackNumber: _wire2api_opt_box_autoadd_u16(arr[5]), + trackTotal: _wire2api_opt_box_autoadd_u16(arr[6]), + discNumber: _wire2api_opt_box_autoadd_u16(arr[7]), + discTotal: _wire2api_opt_box_autoadd_u16(arr[8]), + year: _wire2api_opt_box_autoadd_i32(arr[9]), + genre: _wire2api_opt_String(arr[10]), + picture: _wire2api_opt_box_autoadd_image(arr[11]), + fileSize: _wire2api_opt_box_autoadd_u64(arr[12]), + ); } - ffi.Pointer _api2wire_opt_box_autoadd_i32(int? raw) { - return raw == null ? ffi.nullptr : _api2wire_box_autoadd_i32(raw); + String? _wire2api_opt_String(dynamic raw) { + return raw == null ? null : _wire2api_String(raw); } - ffi.Pointer _api2wire_opt_box_autoadd_image(Image? raw) { - return raw == null ? ffi.nullptr : _api2wire_box_autoadd_image(raw); + double? _wire2api_opt_box_autoadd_f64(dynamic raw) { + return raw == null ? null : _wire2api_box_autoadd_f64(raw); } - ffi.Pointer _api2wire_opt_box_autoadd_u16(int? raw) { - return raw == null ? ffi.nullptr : _api2wire_box_autoadd_u16(raw); + int? _wire2api_opt_box_autoadd_i32(dynamic raw) { + return raw == null ? null : _wire2api_box_autoadd_i32(raw); } - ffi.Pointer _api2wire_opt_box_autoadd_u64(int? raw) { - return raw == null ? ffi.nullptr : _api2wire_box_autoadd_u64(raw); + Image? _wire2api_opt_box_autoadd_image(dynamic raw) { + return raw == null ? null : _wire2api_box_autoadd_image(raw); } - int _api2wire_u16(int raw) { - return raw; + int? _wire2api_opt_box_autoadd_u16(dynamic raw) { + return raw == null ? null : _wire2api_box_autoadd_u16(raw); } - int _api2wire_u64(int raw) { - return raw; + int? _wire2api_opt_box_autoadd_u64(dynamic raw) { + return raw == null ? null : _wire2api_box_autoadd_u64(raw); } - int _api2wire_u8(int raw) { - return raw; + int _wire2api_u16(dynamic raw) { + return raw as int; } - ffi.Pointer _api2wire_uint_8_list(Uint8List raw) { - final ans = inner.new_uint_8_list_0(raw.length); - ans.ref.ptr.asTypedList(raw.length).setAll(0, raw); - return ans; + int _wire2api_u64(dynamic raw) { + return castInt(raw); } - // Section: api_fill_to_wire - - void _api_fill_to_wire_box_autoadd_image( - Image apiObj, ffi.Pointer wireObj) { - _api_fill_to_wire_image(apiObj, wireObj.ref); + int _wire2api_u8(dynamic raw) { + return raw as int; } - void _api_fill_to_wire_box_autoadd_metadata( - Metadata apiObj, ffi.Pointer wireObj) { - _api_fill_to_wire_metadata(apiObj, wireObj.ref); + Uint8List _wire2api_uint_8_list(dynamic raw) { + return raw as Uint8List; } - void _api_fill_to_wire_image(Image apiObj, wire_Image wireObj) { - wireObj.mime_type = _api2wire_String(apiObj.mimeType); - wireObj.data = _api2wire_uint_8_list(apiObj.data); + void _wire2api_unit(dynamic raw) { + return; } +} - void _api_fill_to_wire_metadata(Metadata apiObj, wire_Metadata wireObj) { - wireObj.title = _api2wire_opt_String(apiObj.title); - wireObj.duration_ms = _api2wire_opt_box_autoadd_f64(apiObj.durationMs); - wireObj.artist = _api2wire_opt_String(apiObj.artist); - wireObj.album = _api2wire_opt_String(apiObj.album); - wireObj.album_artist = _api2wire_opt_String(apiObj.albumArtist); - wireObj.track_number = _api2wire_opt_box_autoadd_u16(apiObj.trackNumber); - wireObj.track_total = _api2wire_opt_box_autoadd_u16(apiObj.trackTotal); - wireObj.disc_number = _api2wire_opt_box_autoadd_u16(apiObj.discNumber); - wireObj.disc_total = _api2wire_opt_box_autoadd_u16(apiObj.discTotal); - wireObj.year = _api2wire_opt_box_autoadd_i32(apiObj.year); - wireObj.genre = _api2wire_opt_String(apiObj.genre); - wireObj.picture = _api2wire_opt_box_autoadd_image(apiObj.picture); - wireObj.file_size = _api2wire_opt_box_autoadd_u64(apiObj.fileSize); - } +// Section: api2wire - void _api_fill_to_wire_opt_box_autoadd_image( - Image? apiObj, ffi.Pointer wireObj) { - if (apiObj != null) _api_fill_to_wire_box_autoadd_image(apiObj, wireObj); - } +@protected +double api2wire_f64(double raw) { + return raw; } -// Section: wire2api -String _wire2api_String(dynamic raw) { - return raw as String; +@protected +int api2wire_i32(int raw) { + return raw; } -double _wire2api_box_autoadd_f64(dynamic raw) { - return raw as double; +@protected +int api2wire_u16(int raw) { + return raw; } -int _wire2api_box_autoadd_i32(dynamic raw) { - return raw as int; +@protected +int api2wire_u8(int raw) { + return raw; } -Image _wire2api_box_autoadd_image(dynamic raw) { - return _wire2api_image(raw); -} +// Section: finalizer -int _wire2api_box_autoadd_u16(dynamic raw) { - return raw as int; -} +class RustPlatform extends FlutterRustBridgeBase { + RustPlatform(ffi.DynamicLibrary dylib) : super(RustWire(dylib)); -int _wire2api_box_autoadd_u64(dynamic raw) { - return raw as int; -} +// Section: api2wire -double _wire2api_f64(dynamic raw) { - return raw as double; -} + @protected + ffi.Pointer api2wire_String(String raw) { + return api2wire_uint_8_list(utf8.encoder.convert(raw)); + } -int _wire2api_i32(dynamic raw) { - return raw as int; -} + @protected + ffi.Pointer api2wire_box_autoadd_f64(double raw) { + return inner.new_box_autoadd_f64_0(api2wire_f64(raw)); + } -Image _wire2api_image(dynamic raw) { - final arr = raw as List; - if (arr.length != 2) - throw Exception('unexpected arr length: expect 2 but see ${arr.length}'); - return Image( - mimeType: _wire2api_String(arr[0]), - data: _wire2api_uint_8_list(arr[1]), - ); -} + @protected + ffi.Pointer api2wire_box_autoadd_i32(int raw) { + return inner.new_box_autoadd_i32_0(api2wire_i32(raw)); + } -Metadata _wire2api_metadata(dynamic raw) { - final arr = raw as List; - if (arr.length != 13) - throw Exception('unexpected arr length: expect 13 but see ${arr.length}'); - return Metadata( - title: _wire2api_opt_String(arr[0]), - durationMs: _wire2api_opt_box_autoadd_f64(arr[1]), - artist: _wire2api_opt_String(arr[2]), - album: _wire2api_opt_String(arr[3]), - albumArtist: _wire2api_opt_String(arr[4]), - trackNumber: _wire2api_opt_box_autoadd_u16(arr[5]), - trackTotal: _wire2api_opt_box_autoadd_u16(arr[6]), - discNumber: _wire2api_opt_box_autoadd_u16(arr[7]), - discTotal: _wire2api_opt_box_autoadd_u16(arr[8]), - year: _wire2api_opt_box_autoadd_i32(arr[9]), - genre: _wire2api_opt_String(arr[10]), - picture: _wire2api_opt_box_autoadd_image(arr[11]), - fileSize: _wire2api_opt_box_autoadd_u64(arr[12]), - ); -} + @protected + ffi.Pointer api2wire_box_autoadd_image(Image raw) { + final ptr = inner.new_box_autoadd_image_0(); + _api_fill_to_wire_image(raw, ptr.ref); + return ptr; + } -String? _wire2api_opt_String(dynamic raw) { - return raw == null ? null : _wire2api_String(raw); -} + @protected + ffi.Pointer api2wire_box_autoadd_metadata(Metadata raw) { + final ptr = inner.new_box_autoadd_metadata_0(); + _api_fill_to_wire_metadata(raw, ptr.ref); + return ptr; + } -double? _wire2api_opt_box_autoadd_f64(dynamic raw) { - return raw == null ? null : _wire2api_box_autoadd_f64(raw); -} + @protected + ffi.Pointer api2wire_box_autoadd_u16(int raw) { + return inner.new_box_autoadd_u16_0(api2wire_u16(raw)); + } -int? _wire2api_opt_box_autoadd_i32(dynamic raw) { - return raw == null ? null : _wire2api_box_autoadd_i32(raw); -} + @protected + ffi.Pointer api2wire_box_autoadd_u64(int raw) { + return inner.new_box_autoadd_u64_0(api2wire_u64(raw)); + } -Image? _wire2api_opt_box_autoadd_image(dynamic raw) { - return raw == null ? null : _wire2api_box_autoadd_image(raw); -} + @protected + ffi.Pointer api2wire_opt_String(String? raw) { + return raw == null ? ffi.nullptr : api2wire_String(raw); + } -int? _wire2api_opt_box_autoadd_u16(dynamic raw) { - return raw == null ? null : _wire2api_box_autoadd_u16(raw); -} + @protected + ffi.Pointer api2wire_opt_box_autoadd_f64(double? raw) { + return raw == null ? ffi.nullptr : api2wire_box_autoadd_f64(raw); + } -int? _wire2api_opt_box_autoadd_u64(dynamic raw) { - return raw == null ? null : _wire2api_box_autoadd_u64(raw); -} + @protected + ffi.Pointer api2wire_opt_box_autoadd_i32(int? raw) { + return raw == null ? ffi.nullptr : api2wire_box_autoadd_i32(raw); + } -int _wire2api_u16(dynamic raw) { - return raw as int; -} + @protected + ffi.Pointer api2wire_opt_box_autoadd_image(Image? raw) { + return raw == null ? ffi.nullptr : api2wire_box_autoadd_image(raw); + } -int _wire2api_u64(dynamic raw) { - return raw as int; -} + @protected + ffi.Pointer api2wire_opt_box_autoadd_u16(int? raw) { + return raw == null ? ffi.nullptr : api2wire_box_autoadd_u16(raw); + } -int _wire2api_u8(dynamic raw) { - return raw as int; -} + @protected + ffi.Pointer api2wire_opt_box_autoadd_u64(int? raw) { + return raw == null ? ffi.nullptr : api2wire_box_autoadd_u64(raw); + } -Uint8List _wire2api_uint_8_list(dynamic raw) { - return raw as Uint8List; -} + @protected + int api2wire_u64(int raw) { + return raw; + } + + @protected + ffi.Pointer api2wire_uint_8_list(Uint8List raw) { + final ans = inner.new_uint_8_list_0(raw.length); + ans.ref.ptr.asTypedList(raw.length).setAll(0, raw); + return ans; + } +// Section: finalizer + +// Section: api_fill_to_wire + + void _api_fill_to_wire_box_autoadd_image( + Image apiObj, ffi.Pointer wireObj) { + _api_fill_to_wire_image(apiObj, wireObj.ref); + } + + void _api_fill_to_wire_box_autoadd_metadata( + Metadata apiObj, ffi.Pointer wireObj) { + _api_fill_to_wire_metadata(apiObj, wireObj.ref); + } + + void _api_fill_to_wire_image(Image apiObj, wire_Image wireObj) { + wireObj.mime_type = api2wire_String(apiObj.mimeType); + wireObj.data = api2wire_uint_8_list(apiObj.data); + } -void _wire2api_unit(dynamic raw) { - return; + void _api_fill_to_wire_metadata(Metadata apiObj, wire_Metadata wireObj) { + wireObj.title = api2wire_opt_String(apiObj.title); + wireObj.duration_ms = api2wire_opt_box_autoadd_f64(apiObj.durationMs); + wireObj.artist = api2wire_opt_String(apiObj.artist); + wireObj.album = api2wire_opt_String(apiObj.album); + wireObj.album_artist = api2wire_opt_String(apiObj.albumArtist); + wireObj.track_number = api2wire_opt_box_autoadd_u16(apiObj.trackNumber); + wireObj.track_total = api2wire_opt_box_autoadd_u16(apiObj.trackTotal); + wireObj.disc_number = api2wire_opt_box_autoadd_u16(apiObj.discNumber); + wireObj.disc_total = api2wire_opt_box_autoadd_u16(apiObj.discTotal); + wireObj.year = api2wire_opt_box_autoadd_i32(apiObj.year); + wireObj.genre = api2wire_opt_String(apiObj.genre); + wireObj.picture = api2wire_opt_box_autoadd_image(apiObj.picture); + wireObj.file_size = api2wire_opt_box_autoadd_u64(apiObj.fileSize); + } + + void _api_fill_to_wire_opt_box_autoadd_image( + Image? apiObj, ffi.Pointer wireObj) { + if (apiObj != null) _api_fill_to_wire_box_autoadd_image(apiObj, wireObj); + } } // ignore_for_file: camel_case_types, non_constant_identifier_names, avoid_positional_boolean_parameters, annotate_overrides, constant_identifier_names @@ -358,6 +402,9 @@ void _wire2api_unit(dynamic raw) { /// generated by flutter_rust_bridge class RustWire implements FlutterRustBridgeWireBase { + @internal + late final dartApi = DartApiDl(init_frb_dart_api_dl); + /// Holds the symbol lookup function. final ffi.Pointer Function(String symbolName) _lookup; @@ -371,6 +418,76 @@ class RustWire implements FlutterRustBridgeWireBase { lookup) : _lookup = lookup; + void store_dart_post_cobject( + ptr, + ) { + return _store_dart_post_cobject( + ptr.address, + ); + } + + late final _store_dart_post_cobjectPtr = + _lookup>( + 'store_dart_post_cobject'); + late final _store_dart_post_cobject = + _store_dart_post_cobjectPtr.asFunction(); + + Object get_dart_object( + int ptr, + ) { + return _get_dart_object( + ptr, + ); + } + + late final _get_dart_objectPtr = + _lookup>( + 'get_dart_object'); + late final _get_dart_object = + _get_dart_objectPtr.asFunction(); + + void drop_dart_object( + int ptr, + ) { + return _drop_dart_object( + ptr, + ); + } + + late final _drop_dart_objectPtr = + _lookup>( + 'drop_dart_object'); + late final _drop_dart_object = + _drop_dart_objectPtr.asFunction(); + + int new_dart_opaque( + Object handle, + ) { + return _new_dart_opaque( + handle, + ); + } + + late final _new_dart_opaquePtr = + _lookup>( + 'new_dart_opaque'); + late final _new_dart_opaque = + _new_dart_opaquePtr.asFunction(); + + int init_frb_dart_api_dl( + ffi.Pointer obj, + ) { + return _init_frb_dart_api_dl( + obj, + ); + } + + late final _init_frb_dart_api_dlPtr = + _lookup)>>( + 'init_frb_dart_api_dl'); + late final _init_frb_dart_api_dl = _init_frb_dart_api_dlPtr + .asFunction)>(); + void wire_ping( int port_, ) { @@ -511,35 +628,23 @@ class RustWire implements FlutterRustBridgeWireBase { late final _new_uint_8_list_0 = _new_uint_8_list_0Ptr .asFunction Function(int)>(); - void free_WireSyncReturnStruct( - WireSyncReturnStruct val, - ) { - return _free_WireSyncReturnStruct( - val, - ); - } - - late final _free_WireSyncReturnStructPtr = - _lookup>( - 'free_WireSyncReturnStruct'); - late final _free_WireSyncReturnStruct = _free_WireSyncReturnStructPtr - .asFunction(); - - void store_dart_post_cobject( - covariant ptr, + void free_WireSyncReturn( + WireSyncReturn ptr, ) { - return _store_dart_post_cobject( - ptr.address, + return _free_WireSyncReturn( + ptr, ); } - late final _store_dart_post_cobjectPtr = - _lookup>( - 'store_dart_post_cobject'); - late final _store_dart_post_cobject = - _store_dart_post_cobjectPtr.asFunction(); + late final _free_WireSyncReturnPtr = + _lookup>( + 'free_WireSyncReturn'); + late final _free_WireSyncReturn = + _free_WireSyncReturnPtr.asFunction(); } +class _Dart_Handle extends ffi.Opaque {} + class wire_uint_8_list extends ffi.Struct { external ffi.Pointer ptr; diff --git a/pubspec.yaml b/pubspec.yaml index ab77a58..5d291b3 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -10,14 +10,14 @@ environment: dependencies: flutter: sdk: flutter - flutter_rust_bridge: ^1.41.3 + flutter_rust_bridge: ^1.59.0 ffi: ^2.0.1 dev_dependencies: flutter_test: sdk: flutter flutter_lints: ^2.0.0 - ffigen: ^6.1.2 + ffigen: ^7.2.4 flutter: plugin: diff --git a/rust/Cargo.lock b/rust/Cargo.lock index c58e65c..f3be464 100644 --- a/rust/Cargo.lock +++ b/rust/Cargo.lock @@ -10,18 +10,29 @@ checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" [[package]] name = "allo-isolate" -version = "0.1.13-beta.5" +version = "0.1.14-beta.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c1a52c9b965fdaf940102bcb1a0aef4bc2f56489056f5872cef705651c7972e" +checksum = "692305cf262038708c09c56dd7c7d5387578b032456b427331703fffaa682c49" dependencies = [ + "anyhow", "atomic", + "chrono", +] + +[[package]] +name = "android_system_properties" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311" +dependencies = [ + "libc", ] [[package]] name = "anyhow" -version = "1.0.57" +version = "1.0.68" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "08f9b8508dccb7687a1d6c4ce66b2b0ecef467c94667de27d8d7fe1f8d2a9cdc" +checksum = "2cb2f989d18dd141ab8ae82f64d1a8cdd37e0840f73a406896cf5e99502fab61" [[package]] name = "atomic" @@ -64,18 +75,83 @@ version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" +[[package]] +name = "build-target" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "832133bbabbbaa9fbdba793456a2827627a7d2b8fb96032fa1e7666d7895832b" + +[[package]] +name = "bumpalo" +version = "3.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "572f695136211188308f16ad2ca5c851a712c464060ae6974944458eb83880ba" + +[[package]] +name = "bytemuck" +version = "1.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aaa3a8d9a1ca92e282c96a32d6511b695d7d994d1d102ba85d279f9b2756947f" + [[package]] name = "byteorder" version = "1.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" +[[package]] +name = "cc" +version = "1.0.78" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a20104e2335ce8a659d6dd92a51a767a0c062599c73b343fd152cb401e828c3d" + [[package]] name = "cfg-if" version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "chrono" +version = "0.4.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "16b0a3d9ed01224b22057780a37bb8c5dbfe1be8ba48678e7bf57ec4b385411f" +dependencies = [ + "iana-time-zone", + "js-sys", + "num-integer", + "num-traits", + "time", + "wasm-bindgen", + "winapi", +] + +[[package]] +name = "codespan-reporting" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3538270d33cc669650c4b093848450d380def10c331d38c768e34cac80576e6e" +dependencies = [ + "termcolor", + "unicode-width", +] + +[[package]] +name = "console_error_panic_hook" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a06aeb73f470f66dcdbf7223caeebb85984942f22f1adb2a088cf9668146bbbc" +dependencies = [ + "cfg-if", + "wasm-bindgen", +] + +[[package]] +name = "core-foundation-sys" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5827cebf4670468b8772dd191856768aedcb1b0278a04f989f7766351917b9dc" + [[package]] name = "crc32fast" version = "1.3.2" @@ -85,6 +161,50 @@ dependencies = [ "cfg-if", ] +[[package]] +name = "cxx" +version = "1.0.85" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5add3fc1717409d029b20c5b6903fc0c0b02fa6741d820054f4a2efa5e5816fd" +dependencies = [ + "cc", + "cxxbridge-flags", + "cxxbridge-macro", + "link-cplusplus", +] + +[[package]] +name = "cxx-build" +version = "1.0.85" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b4c87959ba14bc6fbc61df77c3fcfe180fc32b93538c4f1031dd802ccb5f2ff0" +dependencies = [ + "cc", + "codespan-reporting", + "once_cell", + "proc-macro2", + "quote", + "scratch", + "syn", +] + +[[package]] +name = "cxxbridge-flags" +version = "1.0.85" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "69a3e162fde4e594ed2b07d0f83c6c67b745e7f28ce58c6df5e6b6bef99dfb59" + +[[package]] +name = "cxxbridge-macro" +version = "1.0.85" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3e7e2adeb6a0d4a282e581096b06e1791532b7d576dcde5ccd9382acf55db8e6" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "flate2" version = "1.0.24" @@ -97,16 +217,26 @@ dependencies = [ [[package]] name = "flutter_rust_bridge" -version = "1.31.0" +version = "1.59.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7268481c0fb5361be5d004ddb7254008c190788d319a78f3a7cec30e9e44433b" +checksum = "ee0b1f52e02ccd5337765560d35c57d466a12409e454849eeca9dc04a8cfca3a" dependencies = [ "allo-isolate", "anyhow", + "build-target", + "bytemuck", + "cc", + "chrono", + "console_error_panic_hook", "flutter_rust_bridge_macros", + "js-sys", "lazy_static", + "libc", + "log", "parking_lot", "threadpool", + "wasm-bindgen", + "web-sys", ] [[package]] @@ -130,6 +260,30 @@ version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" +[[package]] +name = "iana-time-zone" +version = "0.1.53" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "64c122667b287044802d6ce17ee2ddf13207ed924c712de9a66a5814d5b64765" +dependencies = [ + "android_system_properties", + "core-foundation-sys", + "iana-time-zone-haiku", + "js-sys", + "wasm-bindgen", + "winapi", +] + +[[package]] +name = "iana-time-zone-haiku" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0703ae284fc167426161c2e3f1da3ea71d94b21bedbcc9494e92b28e334e3dca" +dependencies = [ + "cxx", + "cxx-build", +] + [[package]] name = "id3" version = "1.3.0" @@ -141,6 +295,15 @@ dependencies = [ "flate2", ] +[[package]] +name = "js-sys" +version = "0.3.60" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49409df3e3bf0856b916e2ceaca09ee28e6871cf7d9ce97a692cacfdb2a25a47" +dependencies = [ + "wasm-bindgen", +] + [[package]] name = "lazy_static" version = "1.4.0" @@ -153,6 +316,15 @@ version = "0.2.126" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "349d5a591cd28b49e1d1037471617a32ddcda5731b99419008085f72d5a53836" +[[package]] +name = "link-cplusplus" +version = "1.0.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ecd207c9c713c34f95a097a5b029ac2ce6010530c7b49d7fea24d977dede04f5" +dependencies = [ + "cc", +] + [[package]] name = "lock_api" version = "0.4.7" @@ -208,6 +380,25 @@ version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "07dcca13d1740c0a665f77104803360da0bdb3323ecce2e93fa2c959a6d52806" +[[package]] +name = "num-integer" +version = "0.1.45" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "225d3389fb3509a24c93f5c29eb6bde2586b98d9f016636dff58d7c6f7569cd9" +dependencies = [ + "autocfg", + "num-traits", +] + +[[package]] +name = "num-traits" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "578ede34cf02f8924ab9447f50c28075b4d3e5b269972345e7e0372b38c6cdcd" +dependencies = [ + "autocfg", +] + [[package]] name = "num_cpus" version = "1.13.1" @@ -218,11 +409,17 @@ dependencies = [ "libc", ] +[[package]] +name = "once_cell" +version = "1.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6f61fba1741ea2b3d6a1e3178721804bb716a68a6aeba1149b5d52e3d464ea66" + [[package]] name = "parking_lot" -version = "0.12.0" +version = "0.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87f5ec2493a61ac0506c0f4199f99070cbe83857b0337006a30f3e6719b8ef58" +checksum = "3742b2c103b9f06bc9fff0a37ff4912935851bee6d36f3c02bcc755bcfec228f" dependencies = [ "lock_api", "parking_lot_core", @@ -289,6 +486,12 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" +[[package]] +name = "scratch" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ddccb15bcce173023b3fedd9436f882a0739b8dfb45e4f6b6002bee5929f61b2" + [[package]] name = "smallvec" version = "1.8.0" @@ -306,6 +509,15 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "termcolor" +version = "1.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bab24d30b911b2376f3a13cc2cd443142f0c81dda04c118693e35b3835757755" +dependencies = [ + "winapi-util", +] + [[package]] name = "thiserror" version = "1.0.33" @@ -335,12 +547,130 @@ dependencies = [ "num_cpus", ] +[[package]] +name = "time" +version = "0.1.45" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b797afad3f312d1c66a56d11d0316f916356d11bd158fbc6ca6389ff6bf805a" +dependencies = [ + "libc", + "wasi", + "winapi", +] + [[package]] name = "unicode-ident" version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c4f5b37a154999a8f3f98cc23a628d850e154479cd94decf3414696e12e31aaf" +[[package]] +name = "unicode-width" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c0edd1e5b14653f783770bce4a4dabb4a5108a5370a5f5d8cfe8710c361f6c8b" + +[[package]] +name = "wasi" +version = "0.10.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a143597ca7c7793eff794def352d41792a93c481eb1042423ff7ff72ba2c31f" + +[[package]] +name = "wasm-bindgen" +version = "0.2.83" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eaf9f5aceeec8be17c128b2e93e031fb8a4d469bb9c4ae2d7dc1888b26887268" +dependencies = [ + "cfg-if", + "wasm-bindgen-macro", +] + +[[package]] +name = "wasm-bindgen-backend" +version = "0.2.83" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c8ffb332579b0557b52d268b91feab8df3615f265d5270fec2a8c95b17c1142" +dependencies = [ + "bumpalo", + "log", + "once_cell", + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.83" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "052be0f94026e6cbc75cdefc9bae13fd6052cdcaf532fa6c45e7ae33a1e6c810" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.83" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07bc0c051dc5f23e307b13285f9d75df86bfdf816c5721e573dec1f9b8aa193c" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-backend", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.83" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1c38c045535d93ec4f0b4defec448e4291638ee608530863b1e2ba115d4fff7f" + +[[package]] +name = "web-sys" +version = "0.3.60" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bcda906d8be16e728fd5adc5b729afad4e444e106ab28cd1c7256e54fa61510f" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "winapi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + +[[package]] +name = "winapi-util" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" +dependencies = [ + "winapi", +] + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" + [[package]] name = "windows-sys" version = "0.36.1" diff --git a/rust/Cargo.toml b/rust/Cargo.toml index e9f1067..6ac0fa7 100644 --- a/rust/Cargo.toml +++ b/rust/Cargo.toml @@ -13,7 +13,7 @@ name = "rust" path = "src/main.rs" [dependencies] -flutter_rust_bridge = "1" +flutter_rust_bridge = "1.59.0" anyhow = "1" audiotags = "0.4.1" diff --git a/rust/src/bridge_generated.io.rs b/rust/src/bridge_generated.io.rs new file mode 100644 index 0000000..835d812 --- /dev/null +++ b/rust/src/bridge_generated.io.rs @@ -0,0 +1,206 @@ +use super::*; +// Section: wire functions + +#[no_mangle] +pub extern "C" fn wire_ping(port_: i64) { + wire_ping_impl(port_) +} + +#[no_mangle] +pub extern "C" fn wire_read_metadata(port_: i64, file: *mut wire_uint_8_list) { + wire_read_metadata_impl(port_, file) +} + +#[no_mangle] +pub extern "C" fn wire_write_metadata( + port_: i64, + file: *mut wire_uint_8_list, + metadata: *mut wire_Metadata, +) { + wire_write_metadata_impl(port_, file, metadata) +} + +// Section: allocate functions + +#[no_mangle] +pub extern "C" fn new_box_autoadd_f64_0(value: f64) -> *mut f64 { + support::new_leak_box_ptr(value) +} + +#[no_mangle] +pub extern "C" fn new_box_autoadd_i32_0(value: i32) -> *mut i32 { + support::new_leak_box_ptr(value) +} + +#[no_mangle] +pub extern "C" fn new_box_autoadd_image_0() -> *mut wire_Image { + support::new_leak_box_ptr(wire_Image::new_with_null_ptr()) +} + +#[no_mangle] +pub extern "C" fn new_box_autoadd_metadata_0() -> *mut wire_Metadata { + support::new_leak_box_ptr(wire_Metadata::new_with_null_ptr()) +} + +#[no_mangle] +pub extern "C" fn new_box_autoadd_u16_0(value: u16) -> *mut u16 { + support::new_leak_box_ptr(value) +} + +#[no_mangle] +pub extern "C" fn new_box_autoadd_u64_0(value: u64) -> *mut u64 { + support::new_leak_box_ptr(value) +} + +#[no_mangle] +pub extern "C" fn new_uint_8_list_0(len: i32) -> *mut wire_uint_8_list { + let ans = wire_uint_8_list { + ptr: support::new_leak_vec_ptr(Default::default(), len), + len, + }; + support::new_leak_box_ptr(ans) +} + +// Section: related functions + +// Section: impl Wire2Api + +impl Wire2Api for *mut wire_uint_8_list { + fn wire2api(self) -> String { + let vec: Vec = self.wire2api(); + String::from_utf8_lossy(&vec).into_owned() + } +} + +impl Wire2Api for *mut wire_Image { + fn wire2api(self) -> Image { + let wrap = unsafe { support::box_from_leak_ptr(self) }; + Wire2Api::::wire2api(*wrap).into() + } +} +impl Wire2Api for *mut wire_Metadata { + fn wire2api(self) -> Metadata { + let wrap = unsafe { support::box_from_leak_ptr(self) }; + Wire2Api::::wire2api(*wrap).into() + } +} + +impl Wire2Api for wire_Image { + fn wire2api(self) -> Image { + Image { + mime_type: self.mime_type.wire2api(), + data: self.data.wire2api(), + } + } +} +impl Wire2Api for wire_Metadata { + fn wire2api(self) -> Metadata { + Metadata { + title: self.title.wire2api(), + duration_ms: self.duration_ms.wire2api(), + artist: self.artist.wire2api(), + album: self.album.wire2api(), + album_artist: self.album_artist.wire2api(), + track_number: self.track_number.wire2api(), + track_total: self.track_total.wire2api(), + disc_number: self.disc_number.wire2api(), + disc_total: self.disc_total.wire2api(), + year: self.year.wire2api(), + genre: self.genre.wire2api(), + picture: self.picture.wire2api(), + file_size: self.file_size.wire2api(), + } + } +} + +impl Wire2Api> for *mut wire_uint_8_list { + fn wire2api(self) -> Vec { + unsafe { + let wrap = support::box_from_leak_ptr(self); + support::vec_from_leak_ptr(wrap.ptr, wrap.len) + } + } +} +// Section: wire structs + +#[repr(C)] +#[derive(Clone)] +pub struct wire_Image { + mime_type: *mut wire_uint_8_list, + data: *mut wire_uint_8_list, +} + +#[repr(C)] +#[derive(Clone)] +pub struct wire_Metadata { + title: *mut wire_uint_8_list, + duration_ms: *mut f64, + artist: *mut wire_uint_8_list, + album: *mut wire_uint_8_list, + album_artist: *mut wire_uint_8_list, + track_number: *mut u16, + track_total: *mut u16, + disc_number: *mut u16, + disc_total: *mut u16, + year: *mut i32, + genre: *mut wire_uint_8_list, + picture: *mut wire_Image, + file_size: *mut u64, +} + +#[repr(C)] +#[derive(Clone)] +pub struct wire_uint_8_list { + ptr: *mut u8, + len: i32, +} + +// Section: impl NewWithNullPtr + +pub trait NewWithNullPtr { + fn new_with_null_ptr() -> Self; +} + +impl NewWithNullPtr for *mut T { + fn new_with_null_ptr() -> Self { + std::ptr::null_mut() + } +} + +impl NewWithNullPtr for wire_Image { + fn new_with_null_ptr() -> Self { + Self { + mime_type: core::ptr::null_mut(), + data: core::ptr::null_mut(), + } + } +} + +impl NewWithNullPtr for wire_Metadata { + fn new_with_null_ptr() -> Self { + Self { + title: core::ptr::null_mut(), + duration_ms: core::ptr::null_mut(), + artist: core::ptr::null_mut(), + album: core::ptr::null_mut(), + album_artist: core::ptr::null_mut(), + track_number: core::ptr::null_mut(), + track_total: core::ptr::null_mut(), + disc_number: core::ptr::null_mut(), + disc_total: core::ptr::null_mut(), + year: core::ptr::null_mut(), + genre: core::ptr::null_mut(), + picture: core::ptr::null_mut(), + file_size: core::ptr::null_mut(), + } + } +} + +// Section: sync execution mode utility + +#[no_mangle] +pub extern "C" fn free_WireSyncReturn(ptr: support::WireSyncReturn) { + unsafe { + let _ = support::box_from_leak_ptr(ptr); + }; +} diff --git a/rust/src/bridge_generated.rs b/rust/src/bridge_generated.rs index e697f91..73412f4 100644 --- a/rust/src/bridge_generated.rs +++ b/rust/src/bridge_generated.rs @@ -5,20 +5,23 @@ clippy::useless_conversion, clippy::unit_arg, clippy::double_parens, - non_snake_case + non_snake_case, + clippy::too_many_arguments )] // AUTO GENERATED FILE, DO NOT EDIT. -// Generated by `flutter_rust_bridge`. +// Generated by `flutter_rust_bridge`@ 1.59.0. use crate::api::*; +use core::panic::UnwindSafe; use flutter_rust_bridge::*; +use std::ffi::c_void; +use std::sync::Arc; // Section: imports // Section: wire functions -#[no_mangle] -pub extern "C" fn wire_ping(port_: i64) { +fn wire_ping_impl(port_: MessagePort) { FLUTTER_RUST_BRIDGE_HANDLER.wrap( WrapInfo { debug_name: "ping", @@ -28,9 +31,7 @@ pub extern "C" fn wire_ping(port_: i64) { move || move |task_callback| Ok(ping()), ) } - -#[no_mangle] -pub extern "C" fn wire_read_metadata(port_: i64, file: *mut wire_uint_8_list) { +fn wire_read_metadata_impl(port_: MessagePort, file: impl Wire2Api + UnwindSafe) { FLUTTER_RUST_BRIDGE_HANDLER.wrap( WrapInfo { debug_name: "read_metadata", @@ -43,12 +44,10 @@ pub extern "C" fn wire_read_metadata(port_: i64, file: *mut wire_uint_8_list) { }, ) } - -#[no_mangle] -pub extern "C" fn wire_write_metadata( - port_: i64, - file: *mut wire_uint_8_list, - metadata: *mut wire_Metadata, +fn wire_write_metadata_impl( + port_: MessagePort, + file: impl Wire2Api + UnwindSafe, + metadata: impl Wire2Api + UnwindSafe, ) { FLUTTER_RUST_BRIDGE_HANDLER.wrap( WrapInfo { @@ -63,85 +62,13 @@ pub extern "C" fn wire_write_metadata( }, ) } - -// Section: wire structs - -#[repr(C)] -#[derive(Clone)] -pub struct wire_Image { - mime_type: *mut wire_uint_8_list, - data: *mut wire_uint_8_list, -} - -#[repr(C)] -#[derive(Clone)] -pub struct wire_Metadata { - title: *mut wire_uint_8_list, - duration_ms: *mut f64, - artist: *mut wire_uint_8_list, - album: *mut wire_uint_8_list, - album_artist: *mut wire_uint_8_list, - track_number: *mut u16, - track_total: *mut u16, - disc_number: *mut u16, - disc_total: *mut u16, - year: *mut i32, - genre: *mut wire_uint_8_list, - picture: *mut wire_Image, - file_size: *mut u64, -} - -#[repr(C)] -#[derive(Clone)] -pub struct wire_uint_8_list { - ptr: *mut u8, - len: i32, -} - // Section: wrapper structs // Section: static checks // Section: allocate functions -#[no_mangle] -pub extern "C" fn new_box_autoadd_f64_0(value: f64) -> *mut f64 { - support::new_leak_box_ptr(value) -} - -#[no_mangle] -pub extern "C" fn new_box_autoadd_i32_0(value: i32) -> *mut i32 { - support::new_leak_box_ptr(value) -} - -#[no_mangle] -pub extern "C" fn new_box_autoadd_image_0() -> *mut wire_Image { - support::new_leak_box_ptr(wire_Image::new_with_null_ptr()) -} - -#[no_mangle] -pub extern "C" fn new_box_autoadd_metadata_0() -> *mut wire_Metadata { - support::new_leak_box_ptr(wire_Metadata::new_with_null_ptr()) -} - -#[no_mangle] -pub extern "C" fn new_box_autoadd_u16_0(value: u16) -> *mut u16 { - support::new_leak_box_ptr(value) -} - -#[no_mangle] -pub extern "C" fn new_box_autoadd_u64_0(value: u64) -> *mut u64 { - support::new_leak_box_ptr(value) -} - -#[no_mangle] -pub extern "C" fn new_uint_8_list_0(len: i32) -> *mut wire_uint_8_list { - let ans = wire_uint_8_list { - ptr: support::new_leak_vec_ptr(Default::default(), len), - len, - }; - support::new_leak_box_ptr(ans) -} +// Section: related functions // Section: impl Wire2Api @@ -154,18 +81,7 @@ where *mut S: Wire2Api, { fn wire2api(self) -> Option { - if self.is_null() { - None - } else { - Some(self.wire2api()) - } - } -} - -impl Wire2Api for *mut wire_uint_8_list { - fn wire2api(self) -> String { - let vec: Vec = self.wire2api(); - String::from_utf8_lossy(&vec).into_owned() + (!self.is_null()).then(|| self.wire2api()) } } @@ -174,159 +90,60 @@ impl Wire2Api for *mut f64 { unsafe { *support::box_from_leak_ptr(self) } } } - impl Wire2Api for *mut i32 { fn wire2api(self) -> i32 { unsafe { *support::box_from_leak_ptr(self) } } } -impl Wire2Api for *mut wire_Image { - fn wire2api(self) -> Image { - let wrap = unsafe { support::box_from_leak_ptr(self) }; - Wire2Api::::wire2api(*wrap).into() - } -} - -impl Wire2Api for *mut wire_Metadata { - fn wire2api(self) -> Metadata { - let wrap = unsafe { support::box_from_leak_ptr(self) }; - Wire2Api::::wire2api(*wrap).into() - } -} - impl Wire2Api for *mut u16 { fn wire2api(self) -> u16 { unsafe { *support::box_from_leak_ptr(self) } } } - impl Wire2Api for *mut u64 { fn wire2api(self) -> u64 { unsafe { *support::box_from_leak_ptr(self) } } } - impl Wire2Api for f64 { fn wire2api(self) -> f64 { self } } - impl Wire2Api for i32 { fn wire2api(self) -> i32 { self } } -impl Wire2Api for wire_Image { - fn wire2api(self) -> Image { - Image { - mime_type: self.mime_type.wire2api(), - data: self.data.wire2api(), - } - } -} - -impl Wire2Api for wire_Metadata { - fn wire2api(self) -> Metadata { - Metadata { - title: self.title.wire2api(), - duration_ms: self.duration_ms.wire2api(), - artist: self.artist.wire2api(), - album: self.album.wire2api(), - album_artist: self.album_artist.wire2api(), - track_number: self.track_number.wire2api(), - track_total: self.track_total.wire2api(), - disc_number: self.disc_number.wire2api(), - disc_total: self.disc_total.wire2api(), - year: self.year.wire2api(), - genre: self.genre.wire2api(), - picture: self.picture.wire2api(), - file_size: self.file_size.wire2api(), - } - } -} - impl Wire2Api for u16 { fn wire2api(self) -> u16 { self } } - impl Wire2Api for u64 { fn wire2api(self) -> u64 { self } } - impl Wire2Api for u8 { fn wire2api(self) -> u8 { self } } -impl Wire2Api> for *mut wire_uint_8_list { - fn wire2api(self) -> Vec { - unsafe { - let wrap = support::box_from_leak_ptr(self); - support::vec_from_leak_ptr(wrap.ptr, wrap.len) - } - } -} - -// Section: impl NewWithNullPtr - -pub trait NewWithNullPtr { - fn new_with_null_ptr() -> Self; -} - -impl NewWithNullPtr for *mut T { - fn new_with_null_ptr() -> Self { - std::ptr::null_mut() - } -} - -impl NewWithNullPtr for wire_Image { - fn new_with_null_ptr() -> Self { - Self { - mime_type: core::ptr::null_mut(), - data: core::ptr::null_mut(), - } - } -} - -impl NewWithNullPtr for wire_Metadata { - fn new_with_null_ptr() -> Self { - Self { - title: core::ptr::null_mut(), - duration_ms: core::ptr::null_mut(), - artist: core::ptr::null_mut(), - album: core::ptr::null_mut(), - album_artist: core::ptr::null_mut(), - track_number: core::ptr::null_mut(), - track_total: core::ptr::null_mut(), - disc_number: core::ptr::null_mut(), - disc_total: core::ptr::null_mut(), - year: core::ptr::null_mut(), - genre: core::ptr::null_mut(), - picture: core::ptr::null_mut(), - file_size: core::ptr::null_mut(), - } - } -} - // Section: impl IntoDart impl support::IntoDart for Image { - fn into_dart(self) -> support::DartCObject { + fn into_dart(self) -> support::DartAbi { vec![self.mime_type.into_dart(), self.data.into_dart()].into_dart() } } impl support::IntoDartExceptPrimitive for Image {} impl support::IntoDart for Metadata { - fn into_dart(self) -> support::DartCObject { + fn into_dart(self) -> support::DartAbi { vec![ self.title.into_dart(), self.duration_ms.into_dart(), @@ -353,11 +170,8 @@ support::lazy_static! { pub static ref FLUTTER_RUST_BRIDGE_HANDLER: support::DefaultHandler = Default::default(); } -// Section: sync execution mode utility - -#[no_mangle] -pub extern "C" fn free_WireSyncReturnStruct(val: support::WireSyncReturnStruct) { - unsafe { - let _ = support::vec_from_leak_ptr(val.ptr, val.len); - } -} \ No newline at end of file +#[cfg(not(target_family = "wasm"))] +#[path = "bridge_generated.io.rs"] +mod io; +#[cfg(not(target_family = "wasm"))] +pub use io::*;