flutter_rust_bridge icon indicating copy to clipboard operation
flutter_rust_bridge copied to clipboard

`impl ... for ...` doesn't generate code

Open derdilla opened this issue 10 months ago • 2 comments

Describe the bug

Implementing a public trait (tested with Default) for a rust struct doesn't generate corresponding dart code.

Steps to reproduce

  1. In the default template change the simple file to:
pub struct A {
    val: u32
}

impl Default for A {
    fn default() -> Self {
        A {
            val: 0
        }
    }
}

impl A {
    pub fn new() -> Self {
        A {
            val: 0
        }
    }
}
  1. run flutter_rust_bridge_codegen generate && flutter pub get
  2. The generated dart class (file simple.dart) contains the static A.new_instance method but no default method. The new method works as expected

Logs

https://pastebin.com/irT3KWT0 (github said issue is too long)

Expected behavior

I expect the generator to either:

  • Create a static default method in the A dart class (prefered)
  • Create a default function
  • Create some other class/mixin with a default function

Generated binding code

No response

OS

Arch Linux

Version of flutter_rust_bridge_codegen

No response

Flutter info

~/Coding/Flutter/derdilla-desktop/apps/calculator git:[main]
flutter doctor -v
[✓] Flutter (Channel beta, 3.22.0-0.2.pre, on Garuda Linux 6.8.7-AMD-znver3, locale en_US.UTF-8)
    • Flutter version 3.22.0-0.2.pre on channel beta at /home/derdilla/bin/apps/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 312b9e81e9 (2 days ago), 2024-04-18 20:57:54 -0700
    • Engine revision a86e74cf06
    • Dart version 3.4.0 (build 3.4.0-282.2.beta)
    • DevTools version 2.34.2

[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0-rc3)
    • Android SDK at /home/derdilla/Android/Sdk
    • Platform android-34, build-tools 34.0.0-rc3
    • Java binary at: /home/derdilla/.local/share/JetBrains/Toolbox/apps/android-studio/jbr/bin/java
    • Java version OpenJDK Runtime Environment (build 17.0.9+0-17.0.9b1087.7-11185874)
    • All Android licenses accepted.

[✗] Chrome - develop for the web (Cannot find Chrome executable at google-chrome)
    ! Cannot find Chrome. Try setting CHROME_EXECUTABLE to a Chrome executable.

[✓] Linux toolchain - develop for Linux desktop
    • clang version 17.0.6
    • cmake version 3.29.2
    • ninja version 1.11.1
    • pkg-config version 2.1.1

[✓] Android Studio (version 2023.1)
    • Android Studio at /home/derdilla/bin/apps/android-studio
    • 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 17.0.6+0-17.0.6b829.9-10027231)

[✓] Android Studio (version 2023.2)
    • Android Studio at /home/derdilla/.local/share/JetBrains/Toolbox/apps/android-studio
    • 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 17.0.9+0-17.0.9b1087.7-11185874)

[✓] IntelliJ IDEA Ultimate Edition (version 2024.1)
    • IntelliJ at /home/derdilla/.local/share/JetBrains/Toolbox/apps/intellij-idea-ultimate
    • Flutter plugin version 79.0.3
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart

[✓] Connected device (1 available)
    • Linux (desktop) • linux • linux-x64 • Garuda Linux 6.8.7-AMD-znver3

[✓] Network resources
    • All expected network resources are available.

! Doctor found issues in 1 category.

Version of clang++

17.0.6 (clang --version)

Additional context

No response

derdilla avatar Apr 21 '24 08:04 derdilla

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

welcome[bot] avatar Apr 21 '24 08:04 welcome[bot]

Hi, yes this is not scanned currently, but it may not be hard to implement it (since impl Sth for A is surely almost identical to impl A). Feel free to PR for it, alternatively I may work on it in the next batch!

fzyzcjy avatar Apr 21 '24 09:04 fzyzcjy

Close since implemented :)

fzyzcjy avatar Jun 06 '24 09:06 fzyzcjy

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.

github-actions[bot] avatar Jun 20 '24 10:06 github-actions[bot]