fzyzcjy / flutter_rust_bridge

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

Returning vec of enum variants fails to build [Bug] #676

Closed smokytheangel0 closed 1 year ago

smokytheangel0 commented 2 years ago

Describe the bug

I am using the bridge template, started at v1.41.3, and after encountering the issue I updated to v1.43.0, and from flutter 3.0 to flutter 3.3. I have been using rustc 1.63.0 (4b91a6ea7 2022-08-08), dart 2.18 and windows 10.0.19043. The issue persisted in each of the versions described.

pub fn search_local_items(input: String) -> Vec<Item> {
    use fuzzy_matcher::skim::SkimMatcherV2;
    use fuzzy_matcher::FuzzyMatcher;
    use std::str::FromStr;
    use strum::{Display, EnumString, EnumVariantNames, VariantNames};
    let matcher = SkimMatcherV2::default();
    let mut display_items: Vec<Item> = vec![];
    for item_string in Item::VARIANTS.iter() {
        if matcher.fuzzy_match(item_string, &input).is_some() {
            let item = match Item::from_str(item_string) {
                Ok(item) => display_items.push(item),
                Err(err) => {
                    panic!(
                        "item string was not in Item enum despite being generated from Item: {err}"
                    )
                }
            };
        }
    }
    display_items
}

cargo build returns this error:

error[E0277]: the trait bound `Vec<Item>: IntoDart` is not satisfied
  --> src\bridge_generated.rs:65:33
   |
65 |     FLUTTER_RUST_BRIDGE_HANDLER.wrap(
   |                                 ^^^^ the trait `IntoDart` is not implemented for `Vec<Item>`
   |
   = help: the following other types implement trait `IntoDart`:
             Vec<T>
             Vec<f32>
             Vec<f64>
             Vec<i16>
             Vec<i32>
             Vec<i64>
             Vec<i8>
             Vec<u16>
           and 3 others
note: required by a bound in `wrap`
  --> C:\Users\wiggle\.cargo\registry\src\github.com-1ecc6299db9ec823\flutter_rust_bridge-1.43.0\src\handler.rs:55:18
   |
55 |         TaskRet: IntoDart;
   |                  ^^^^^^^^ required by this bound in `wrap`

Whats weird is this same function compiled fine earlier, the only changes between working and not was some field name refactors in an unrelated file.

Codegen logs with RUST_LOG=debug environment variable

set RUST_LOG=debug flutter_rust_bridge_codegen /.../ does not seem to output anything more than usual >>

[2022-09-06T23:58:44Z INFO  lib_flutter_rust_bridge_codegen] Picked config: Opts { rust_input_path: "C:/Users/wiggle/Desktop/flutter_rust_bridge_template//native/src/api.rs", dart_output_path: "C:/Users/wiggle/Desktop/flutter_rust_bridge_template//lib/bridge_generated.dart", dart_decl_output_path: None, c_output_path: 
["C:/Users/wiggle/Desktop/flutter_rust_bridge_template//ios/Runner/bridge_generated.h", "C:/Users/wiggle/Desktop/flutter_rust_bridge_template//macos/Runner/bridge_generated.h"], rust_crate_dir: "C:/Users/wiggle/Desktop/flutter_rust_bridge_template/native", rust_output_path: "C:/Users/wiggle/Desktop/flutter_rust_bridge_template//native/src\\bridge_generated.rs", class_name: "Native", dart_format_line_length: 80, skip_add_mod_to_lib: false, llvm_path: ["C:/Program", "Files/LLVM/bin"], llvm_compiler_opts: "", manifest_path: "C:/Users/wiggle/Desktop/flutter_rust_bridge_template/native\\Cargo.toml", dart_root: Some("C:/Users/wiggle/Desktop/flutter_rust_bridge_template"), build_runner: true, block_index: BlockIndex(0), skip_deps_check: false }
[2022-09-06T23:58:44Z INFO  lib_flutter_rust_bridge_codegen] Phase: Parse source code to AST, then to IR
[2022-09-06T23:58:45Z INFO  lib_flutter_rust_bridge_codegen] Phase: Transform IR
[2022-09-06T23:58:45Z INFO  lib_flutter_rust_bridge_codegen] Phase: Generate Rust code
[2022-09-06T23:58:45Z INFO  lib_flutter_rust_bridge_codegen] Phase: Generate Dart code
[2022-09-06T23:58:45Z INFO  lib_flutter_rust_bridge_codegen] Phase: Other things
[2022-09-06T23:58:46Z INFO  cbindgen::bindgen::parser] Take native::Platform - opaque (Enum is not marked with a valid #[repr(prim)] or #[repr(C)].).
[2022-09-06T23:58:46Z INFO  cbindgen::bindgen::parser] Take native::wire_platform.
[2022-09-06T23:58:46Z INFO  cbindgen::bindgen::parser] Take native::wire_rust_release_mode.
[2022-09-06T23:58:46Z INFO  cbindgen::bindgen::parser] Take native::wire_get_nutrition.
[2022-09-06T23:58:46Z INFO  cbindgen::bindgen::parser] Take native::wire_search_local_items.
[2022-09-06T23:58:46Z INFO  cbindgen::bindgen::parser] Take native::wire_uint_8_list.
[2022-09-06T23:58:46Z INFO  cbindgen::bindgen::parser] Take native::new_uint_8_list_0.
[2022-09-06T23:58:46Z INFO  cbindgen::bindgen::parser] Take native::free_WireSyncReturnStruct.
[2022-09-06T23:58:46Z INFO  cbindgen::bindgen::parser] Take native::DartPort.
[2022-09-06T23:58:46Z INFO  cbindgen::bindgen::parser] Take native::DartPostCObjectFnType.
[2022-09-06T23:58:46Z INFO  cbindgen::bindgen::parser] Take native::store_dart_post_cobject.
[2022-09-06T23:58:46Z INFO  cbindgen::bindgen::parser] Take native::WireSyncReturnStruct.
[2022-09-06T23:58:46Z INFO  cbindgen::bindgen::parser] Take native::Item.
[2022-09-06T23:58:46Z INFO  cbindgen::bindgen::parser] Take native::Nutrition.
[2022-09-06T23:58:46Z INFO  cbindgen::bindgen::parser] Take native::ItemInfo.
[2022-09-06T23:59:02Z INFO  lib_flutter_rust_bridge_codegen] Success!
[2022-09-06T23:59:02Z INFO  flutter_rust_bridge_codegen] Now go and use it :)

To Reproduce

src/items.rs

use strum::{Display, EnumString, EnumVariantNames, VariantNames};

#[repr(C)]
#[derive(EnumString, Display, Debug, EnumVariantNames)]
#[strum(ascii_case_insensitive, serialize_all = "title_case")]
pub enum Item {
    #[strum(serialize = "large chicken egg")]
    LargeChickenEgg,
    #[strum(serialize = "large chicken egg yolk")]
    LargeChickenEggYolk,
    #[strum(serialize = "large chicken egg white")]
    LargeChickenEggWhite,
    #[strum(serialize = "table salt")]
    TableSalt,
    #[strum(serialize = "table sugar")]
    TableSugar,
    #[strum(serialize = "water")]
    Water,
    #[strum(serialize = "wheat flour")]
    WheatFlour,
    #[strum(serialize = "active dry yeast")]
    ActiveDryYeast,
    #[strum(serialize = "cow butter")]
    CowButter,
}

Cargo.toml

[package]
name = "native"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[lib]
crate-type = ["cdylib", "staticlib", "rlib"]

[dependencies]
anyhow = "1"
flutter_rust_bridge = "1"
fuzzy-matcher = "0.3.7"
strum = { version = "0.24.1", features = ["strum_macros", "derive"] }

Expected behavior

I expect the code to compile.

Generated binding code

// 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

import 'dart:convert';
import 'dart:typed_data';

import 'dart:convert';
import 'dart:typed_data';
import 'package:flutter_rust_bridge/flutter_rust_bridge.dart';
import 'dart:ffi' as ffi;

abstract class Native {
  Future<Platform> platform({dynamic hint});

  FlutterRustBridgeTaskConstMeta get kPlatformConstMeta;

  Future<bool> rustReleaseMode({dynamic hint});

  FlutterRustBridgeTaskConstMeta get kRustReleaseModeConstMeta;

  Future<ItemInfo> getNutrition({required Item item, dynamic hint});

  FlutterRustBridgeTaskConstMeta get kGetNutritionConstMeta;

  Future<List<Item>> searchLocalItems({required String input, dynamic hint});

  FlutterRustBridgeTaskConstMeta get kSearchLocalItemsConstMeta;
}

enum Item {
  LargeChickenEgg,
  LargeChickenEggYolk,
  LargeChickenEggWhite,
  TableSalt,
  TableSugar,
  Water,
  WheatFlour,
  ActiveDryYeast,
  CowButter,
}

class ItemInfo {
  final Nutrition? nutrition;

  ItemInfo({
    this.nutrition,
  });
}

class Nutrition {
  final Item variant;
  final double? unitWeight;
  final double literWeight;
  final double calories;
  final double caloriesFromFat;
  final double totalFatWeight;
  final double saturatedFatWeight;
  final double polyunsaturatedFatWeight;
  final double monounsaturatedFatWeight;
  final double cholesterolWeight;
  final double sodiumWeight;
  final double potassiumWeight;
  final double carbohydrateWeight;
  final double fiberWeight;
  final double sugarWeight;
  final double proteinWeight;

  Nutrition({
    required this.variant,
    this.unitWeight,
    required this.literWeight,
    required this.calories,
    required this.caloriesFromFat,
    required this.totalFatWeight,
    required this.saturatedFatWeight,
    required this.polyunsaturatedFatWeight,
    required this.monounsaturatedFatWeight,
    required this.cholesterolWeight,
    required this.sodiumWeight,
    required this.potassiumWeight,
    required this.carbohydrateWeight,
    required this.fiberWeight,
    required this.sugarWeight,
    required this.proteinWeight,
  });
}

enum Platform {
  Unknown,
  Android,
  Ios,
  Windows,
  Unix,
  MacIntel,
  MacApple,
  Wasm,
}

class NativeImpl extends FlutterRustBridgeBase<NativeWire> implements Native {
  factory NativeImpl(ffi.DynamicLibrary dylib) =>
      NativeImpl.raw(NativeWire(dylib));

  NativeImpl.raw(NativeWire inner) : super(inner);

  Future<Platform> platform({dynamic hint}) =>
      executeNormal(FlutterRustBridgeTask(
        callFfi: (port_) => inner.wire_platform(port_),
        parseSuccessData: _wire2api_platform,
        constMeta: kPlatformConstMeta,
        argValues: [],
        hint: hint,
      ));

  FlutterRustBridgeTaskConstMeta get kPlatformConstMeta =>
      const FlutterRustBridgeTaskConstMeta(
        debugName: "platform",
        argNames: [],
      );

  Future<bool> rustReleaseMode({dynamic hint}) =>
      executeNormal(FlutterRustBridgeTask(
        callFfi: (port_) => inner.wire_rust_release_mode(port_),
        parseSuccessData: _wire2api_bool,
        constMeta: kRustReleaseModeConstMeta,
        argValues: [],
        hint: hint,
      ));

  FlutterRustBridgeTaskConstMeta get kRustReleaseModeConstMeta =>
      const FlutterRustBridgeTaskConstMeta(
        debugName: "rust_release_mode",
        argNames: [],
      );

  Future<ItemInfo> getNutrition({required Item item, dynamic hint}) =>
      executeNormal(FlutterRustBridgeTask(
        callFfi: (port_) =>
            inner.wire_get_nutrition(port_, _api2wire_item(item)),
        parseSuccessData: _wire2api_item_info,
        constMeta: kGetNutritionConstMeta,
        argValues: [item],
        hint: hint,
      ));

  FlutterRustBridgeTaskConstMeta get kGetNutritionConstMeta =>
      const FlutterRustBridgeTaskConstMeta(
        debugName: "get_nutrition",
        argNames: ["item"],
      );

  Future<List<Item>> searchLocalItems({required String input, dynamic hint}) =>
      executeNormal(FlutterRustBridgeTask(
        callFfi: (port_) =>
            inner.wire_search_local_items(port_, _api2wire_String(input)),
        parseSuccessData: _wire2api_list_item,
        constMeta: kSearchLocalItemsConstMeta,
        argValues: [input],
        hint: hint,
      ));

  FlutterRustBridgeTaskConstMeta get kSearchLocalItemsConstMeta =>
      const FlutterRustBridgeTaskConstMeta(
        debugName: "search_local_items",
        argNames: ["input"],
      );

  // Section: api2wire
  ffi.Pointer<wire_uint_8_list> _api2wire_String(String raw) {
    return _api2wire_uint_8_list(utf8.encoder.convert(raw));
  }

  int _api2wire_i32(int raw) {
    return raw;
  }

  int _api2wire_item(Item raw) {
    return _api2wire_i32(raw.index);
  }

  int _api2wire_u8(int raw) {
    return raw;
  }

  ffi.Pointer<wire_uint_8_list> _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: api_fill_to_wire

}

// Section: wire2api
bool _wire2api_bool(dynamic raw) {
  return raw as bool;
}

double _wire2api_box_autoadd_f64(dynamic raw) {
  return raw as double;
}

Nutrition _wire2api_box_autoadd_nutrition(dynamic raw) {
  return _wire2api_nutrition(raw);
}

double _wire2api_f64(dynamic raw) {
  return raw as double;
}

int _wire2api_i32(dynamic raw) {
  return raw as int;
}

Item _wire2api_item(dynamic raw) {
  return Item.values[raw];
}

ItemInfo _wire2api_item_info(dynamic raw) {
  final arr = raw as List<dynamic>;
  if (arr.length != 1)
    throw Exception('unexpected arr length: expect 1 but see ${arr.length}');
  return ItemInfo(
    nutrition: _wire2api_opt_box_autoadd_nutrition(arr[0]),
  );
}

List<Item> _wire2api_list_item(dynamic raw) {
  return (raw as List<dynamic>).map(_wire2api_item).toList();
}

Nutrition _wire2api_nutrition(dynamic raw) {
  final arr = raw as List<dynamic>;
  if (arr.length != 16)
    throw Exception('unexpected arr length: expect 16 but see ${arr.length}');
  return Nutrition(
    variant: _wire2api_item(arr[0]),
    unitWeight: _wire2api_opt_box_autoadd_f64(arr[1]),
    literWeight: _wire2api_f64(arr[2]),
    calories: _wire2api_f64(arr[3]),
    caloriesFromFat: _wire2api_f64(arr[4]),
    totalFatWeight: _wire2api_f64(arr[5]),
    saturatedFatWeight: _wire2api_f64(arr[6]),
    polyunsaturatedFatWeight: _wire2api_f64(arr[7]),
    monounsaturatedFatWeight: _wire2api_f64(arr[8]),
    cholesterolWeight: _wire2api_f64(arr[9]),
    sodiumWeight: _wire2api_f64(arr[10]),
    potassiumWeight: _wire2api_f64(arr[11]),
    carbohydrateWeight: _wire2api_f64(arr[12]),
    fiberWeight: _wire2api_f64(arr[13]),
    sugarWeight: _wire2api_f64(arr[14]),
    proteinWeight: _wire2api_f64(arr[15]),
  );
}

double? _wire2api_opt_box_autoadd_f64(dynamic raw) {
  return raw == null ? null : _wire2api_box_autoadd_f64(raw);
}

Nutrition? _wire2api_opt_box_autoadd_nutrition(dynamic raw) {
  return raw == null ? null : _wire2api_box_autoadd_nutrition(raw);
}

Platform _wire2api_platform(dynamic raw) {
  return Platform.values[raw];
}

// ignore_for_file: camel_case_types, non_constant_identifier_names, avoid_positional_boolean_parameters, annotate_overrides, constant_identifier_names

// AUTO GENERATED FILE, DO NOT EDIT.
//
// Generated by `package:ffigen`.

/// generated by flutter_rust_bridge
class NativeWire implements FlutterRustBridgeWireBase {
  /// Holds the symbol lookup function.
  final ffi.Pointer<T> Function<T extends ffi.NativeType>(String symbolName)
      _lookup;

  /// The symbols are looked up in [dynamicLibrary].
  NativeWire(ffi.DynamicLibrary dynamicLibrary)
      : _lookup = dynamicLibrary.lookup;

  /// The symbols are looked up with [lookup].
  NativeWire.fromLookup(
      ffi.Pointer<T> Function<T extends ffi.NativeType>(String symbolName)
          lookup)
      : _lookup = lookup;

  void wire_platform(
    int port_,
  ) {
    return _wire_platform(
      port_,
    );
  }

  late final _wire_platformPtr =
      _lookup<ffi.NativeFunction<ffi.Void Function(ffi.Int64)>>(
          'wire_platform');
  late final _wire_platform =
      _wire_platformPtr.asFunction<void Function(int)>();

  void wire_rust_release_mode(
    int port_,
  ) {
    return _wire_rust_release_mode(
      port_,
    );
  }

  late final _wire_rust_release_modePtr =
      _lookup<ffi.NativeFunction<ffi.Void Function(ffi.Int64)>>(
          'wire_rust_release_mode');
  late final _wire_rust_release_mode =
      _wire_rust_release_modePtr.asFunction<void Function(int)>();

  void wire_get_nutrition(
    int port_,
    int item,
  ) {
    return _wire_get_nutrition(
      port_,
      item,
    );
  }

  late final _wire_get_nutritionPtr =
      _lookup<ffi.NativeFunction<ffi.Void Function(ffi.Int64, ffi.Int32)>>(
          'wire_get_nutrition');
  late final _wire_get_nutrition =
      _wire_get_nutritionPtr.asFunction<void Function(int, int)>();

  void wire_search_local_items(
    int port_,
    ffi.Pointer<wire_uint_8_list> input,
  ) {
    return _wire_search_local_items(
      port_,
      input,
    );
  }

  late final _wire_search_local_itemsPtr = _lookup<
      ffi.NativeFunction<
          ffi.Void Function(ffi.Int64,
              ffi.Pointer<wire_uint_8_list>)>>('wire_search_local_items');
  late final _wire_search_local_items = _wire_search_local_itemsPtr
      .asFunction<void Function(int, ffi.Pointer<wire_uint_8_list>)>();

  ffi.Pointer<wire_uint_8_list> new_uint_8_list_0(
    int len,
  ) {
    return _new_uint_8_list_0(
      len,
    );
  }

  late final _new_uint_8_list_0Ptr = _lookup<
      ffi.NativeFunction<
          ffi.Pointer<wire_uint_8_list> Function(
              ffi.Int32)>>('new_uint_8_list_0');
  late final _new_uint_8_list_0 = _new_uint_8_list_0Ptr
      .asFunction<ffi.Pointer<wire_uint_8_list> Function(int)>();

  void free_WireSyncReturnStruct(
    WireSyncReturnStruct val,
  ) {
    return _free_WireSyncReturnStruct(
      val,
    );
  }

  late final _free_WireSyncReturnStructPtr =
      _lookup<ffi.NativeFunction<ffi.Void Function(WireSyncReturnStruct)>>(
          'free_WireSyncReturnStruct');
  late final _free_WireSyncReturnStruct = _free_WireSyncReturnStructPtr
      .asFunction<void Function(WireSyncReturnStruct)>();

  void store_dart_post_cobject(
    DartPostCObjectFnType ptr,
  ) {
    return _store_dart_post_cobject(
      ptr,
    );
  }

  late final _store_dart_post_cobjectPtr =
      _lookup<ffi.NativeFunction<ffi.Void Function(DartPostCObjectFnType)>>(
          'store_dart_post_cobject');
  late final _store_dart_post_cobject = _store_dart_post_cobjectPtr
      .asFunction<void Function(DartPostCObjectFnType)>();
}

class wire_uint_8_list extends ffi.Struct {
  external ffi.Pointer<ffi.Uint8> ptr;

  @ffi.Int32()
  external int len;
}

typedef DartPostCObjectFnType = ffi.Pointer<
    ffi.NativeFunction<ffi.Bool Function(DartPort, ffi.Pointer<ffi.Void>)>>;
typedef DartPort = ffi.Int64;

OS

Windows 10.0.19043

Version of flutter_rust_bridge_codegen

v1.41.3 and v1.43.0

Flutter info

Flutter 3.3.0 • channel stable • https://github.com/flutter/flutter.git
Framework • revision ffccd96b62 (8 days ago) • 2022-08-29 17:28:57 -0700
Engine • revision 5e9e0e0aa8
Tools • Dart 2.18.0 • DevTools 2.15.0
PS C:\Users\wiggle> flutter doctor -v
[√] Flutter (Channel stable, 3.3.0, on Microsoft Windows [Version 10.0.19043.1889],
    locale en-US)
    • Flutter version 3.3.0 on channel stable at C:\Users\wiggle\Desktop\flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision ffccd96b62 (8 days ago), 2022-08-29 17:28:57 -0700
    • Engine revision 5e9e0e0aa8
    • Dart version 2.18.0
    • DevTools version 2.15.0

Checking Android licenses is taking an unexpectedly long time...[√] Android toolchain - develop for Android devices (Android SDK version 32.0.0)
    • Android SDK at C:\Users\wiggle\AppData\Local\Android\sdk
    • Platform android-32, build-tools 32.0.0
    • Java binary at: C:\Program Files\Android\Android Studio1\jre\bin\java
    • Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7249189)
    • All Android licenses accepted.

[√] Chrome - develop for the web
    • Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe

[√] Visual Studio - develop for Windows (Visual Studio Build Tools 2022 17.3.0)
    • Visual Studio at C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools
    • Visual Studio Build Tools 2022 version 17.3.32804.467
    • Windows 10 SDK version 10.0.19041.0

[√] Android Studio (version 2020.3)
    • Android Studio at C:\Program Files\Android\Android Studio1
    • Flutter plugin can be installed from:
       https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
       https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7249189)

[√] VS Code (version 1.71.0)
    • VS Code at C:\Users\wiggle\AppData\Local\Programs\Microsoft VS Code
    • Flutter extension version 3.32.0

[√] Connected device (3 available)
    • Windows (desktop) • windows • windows-x64    • Microsoft Windows [Version
      10.0.19043.1889]
    • Chrome (web)      • chrome  • web-javascript • Google Chrome 104.0.5112.81
    • Edge (web)        • edge    • web-javascript • Microsoft Edge 105.0.1343.27

[√] HTTP Host Availability
    • All required HTTP hosts are available

• No issues found!

Version of clang++

14.0.6

Version of ffigen

6.0.1

Additional context

No response

welcome[bot] commented 2 years ago

Hi! Thanks for opening your first issue here! :smile:

fzyzcjy commented 2 years ago

Firstly, try Vec<Box<Item>>

fzyzcjy commented 2 years ago

Whats weird is this same function compiled fine earlier, the only changes between working and not was some field name refactors in an unrelated file.

Could you please provide a minimal reproducible sample? In other words, a almost-blank repository with few lines of code that reproduce the bug.

I guess by creating this min reproducible sample you will find out the cause.

smokytheangel0 commented 2 years ago

You are quick, sir. I will do that and let you know.

smokytheangel0 commented 2 years ago

I have a minimal example which gives the same error, https://github.com/smokytheangel0/frb_minimal.

I have not created a repo in a long time, so if I did something wrong please let me know. Not sure how to diff this and the flutter_rust_bridge_template starting file, so I hope you know. I had to modify the just file for the minimal because I have few brain cells left.

fzyzcjy commented 2 years ago

Rough idea: Maybe the Item forget to implement IntoDartExceptPrimitive, so https://github.com/sunshine-protocol/allo-isolate/blob/ba1d3ee8e6d12b37d8ca63c1c13a8ff563aa5625/src/into_dart.rs#L242 does not auto apply.

Please ensure you have used the latest:

And feel free to PR!

smokytheangel0 commented 2 years ago

ok thanks for the internal info, I will try and manually implement IntoDartExceptPrimative and I will try and install a newer version of codegen from cargo. I will look at the codegen and see if I can figure out how to make it do automagically if I figure out a solution in my code.

fzyzcjy commented 2 years ago

try and manually implement IntoDartExceptPrimative

That should be done automatically. But anyway manually adding it can quickly test whether it is the cause.

I will look at the codegen and see if I can figure out how to make it do automagically if I figure out a solution in my code.

Take your time and looking forward to your PR!

smokytheangel0 commented 2 years ago

after looking through the codegen, I can see where it adds the impl support::IntoDartExceptPrimitive to the generated_bridge lines in impl_intodart() in ty_enum.rs and the format isn't conditional, maybe later the last line is clobbered by a successive process, but I haven't gotten there yet.

smokytheangel0 commented 2 years ago

its also missing the newline (or String::new()) in the generated output, so the very next thing in generated_bridge lines is the next item presumably from the map operation near the invocation of generate_impl_intodart() in mod.rs. I hope I am understanding this right.

fzyzcjy commented 2 years ago

maybe later the last line is clobbered by a successive process, but I haven't gotten there yet.

IIRC nothing is removed once generated, in frb.

https://github.com/fzyzcjy/flutter_rust_bridge/search?q=IntoDartExceptPrimitive Guess you are right

its also missing the newline (or String::new()) in the generated output

Btw we do run code formatter after generation so not sure whether your "missing newline" comes from this

smokytheangel0 commented 2 years ago

Thanks

fzyzcjy commented 2 years ago

You are welcome!

smokytheangel0 commented 1 year ago

The only thing I have found so far is an explicit newline in the format when structs are generated, but no such newline in the enum version of the format. How do I use my local codegen for a bridge_template project, when I have previously installed it through cargo?

fzyzcjy commented 1 year ago

How do I use my local codegen for a bridge_template project

It is nothing but a rust binary so just cargo run etc

stale[bot] commented 1 year ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

github-actions[bot] commented 1 year ago

This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new issue.