flutter_rust_bridge icon indicating copy to clipboard operation
flutter_rust_bridge copied to clipboard

Implement `impl ... for ...`

Open derdilla opened this issue 10 months ago • 2 comments

Changes

Generates methods when implementing traits for structs.

Fixes #1894

Also Fixes a typo on the website.

Checklist

  • [X] An issue to be fixed by this PR is listed above.
  • [X] New tests are added to ensure new features are working. Please refer to this page to see how to add a test.
  • [ ] ./frb_internal precommit --mode slow (or fast) is run (it internal runs code generator, does auto formatting, etc).
  • [ ] If this PR adds/changes features, documentations (in the ./website folder) are updated.
  • [ ] CI is passing. Please refer to this page to see how to solve a failed CI.

Running ./frb_internal precommit --mode slow locally always results in compilation errors/panics and changes a bunch of tracked files, even on the master branch. It would be great if someone could help me resolve this.

I'm also unsure how to use twin tests and left that part out.

derdilla avatar Apr 21 '24 14:04 derdilla

Hi! Thanks for opening this pull request! :smile:

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

Running ./frb_internal precommit --mode slow locally always results in compilation errors/panics and changes a bunch of tracked files, even on the master branch. It would be great if someone could help me resolve this.

Then maybe ./frb_internal generate-internal-frb-example-pure-dart ; ./frb_internal precommit-generate

I'm also unsure how to use twin tests and left that part out.

It is auto generated (by commands above), no worries

fzyzcjy avatar Apr 21 '24 23:04 fzyzcjy

Hopefully, this feature could be achieved soon.

In my case, there is an enum like this:

#[derive(Debug)]
pub enum ProxyNodeEnum {
    Trojan(TrojanNode),
    VMess(VMessNode),
    VLESS(VLessNode),
}

impl ProxyNode for ProxyNodeEnum {
....
    fn hostname(&self) -> &str {
        match self {
            ProxyNodeEnum::Trojan(node) => &node.hostname,
            ProxyNodeEnum::VMess(node) => &node.host,
            ProxyNodeEnum::VLESS(node) => &node.hostname,
        }
    }

    fn port(&self) -> u16 {
        match self {
            ProxyNodeEnum::Trojan(node) => node.port,
            ProxyNodeEnum::VMess(node) => node.port,
            ProxyNodeEnum::VLESS(node) => node.port,
        }
    }
}

and there is an API return Vec<ProxyNodeEnum>, and port() and hostname() is required to invoke in Dart.

dbsxdbsx avatar May 31 '24 13:05 dbsxdbsx

This is needed when implementing auto scanning of external types, thus I will continue on it.

I will merge to feat/12137 and continue there.

fzyzcjy avatar Jun 03 '24 08:06 fzyzcjy

@all-contributors please add @NobodyForNothing for code,doc

fzyzcjy avatar Jun 03 '24 08:06 fzyzcjy

@fzyzcjy

I've put up a pull request to add @NobodyForNothing! :tada:

allcontributors[bot] avatar Jun 03 '24 08:06 allcontributors[bot]

Hi! Congrats on merging your first pull request! :tada:

welcome[bot] avatar Jun 03 '24 09:06 welcome[bot]

@fzyzcjy thank you for continuing this, I got a bit overwhelmed with the codebase and kinda forgot about this tbh.

A fair warning: Be careful when using this code. At this stage this was primarily me trying to understand the necessary changes and by no means a production ready implementation.

derdilla avatar Jun 06 '24 09:06 derdilla

No worries, I made some necessary changes, and there are CI and thousands of tests to protect us as well!

fzyzcjy avatar Jun 06 '24 09:06 fzyzcjy