Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement operator overloading methods (for external opaque types) #1924

Closed
vhdirk opened this issue May 6, 2024 · 5 comments · Fixed by #1958
Closed

Implement operator overloading methods (for external opaque types) #1924

vhdirk opened this issue May 6, 2024 · 5 comments · Fixed by #1958
Labels
enhancement New feature or request

Comments

@vhdirk
Copy link

vhdirk commented May 6, 2024

I am implementing a derivation of a Semver in rust. Since there's a fair bit of logic behind it, I want to implement it as an opaque type.
And since the type is implemented in an external rust crate (from: https://cjycode.com/flutter_rust_bridge/guides/miscellaneous/methods), it looks like this:

#[frb(external)]
impl MyVersion {
    #[frb(sync)]
    pub fn new(
        _major: u8,
        _minor: u8,
        _patch: u8,
        _extrabit: u8,
        _modifier: u8,
    ) -> Self {
    }

Now, I'd like to be able to use the dart comparison overloads (==,>,=>, etc) to make the api nicer to work with (Strict reference/pointer equality is not important). In the docs, you describe that this can be implemented using arbitrary dart_code (https://cjycode.com/flutter_rust_bridge/guides/miscellaneous/dart-code). However, that annotation seems only usable on struct definitions, not on impl blocks.
I think that, ideally, operators should be first-class citizens, much like pyo3 handles magic functions. Probably even something simple like function renaming #[frb(name="operator==")] would work, although then you'd still need to somehow declare the need for @overload.

What do you think?

@vhdirk vhdirk added the enhancement New feature or request label May 6, 2024
Copy link

welcome bot commented May 6, 2024

Hi! Thanks for opening your first issue here! 😄

@fzyzcjy
Copy link
Owner

fzyzcjy commented May 6, 2024

Looks pretty reasonable! One way may be the rename you mentioned, and another way may be utilize the PartialEq / Eq / Ord / ....

Btw I am not very sure, where do you want to add @overload? IMHO the solutions can be done without it.

@vhdirk
Copy link
Author

vhdirk commented May 7, 2024

I meant @override in Dart. Since that is what things like operator== require

@fzyzcjy
Copy link
Owner

fzyzcjy commented May 7, 2024

I see. Indeed IIRC that is optional - the linter will be unhappy without it, but it is just linter instead of compiler, and you can // ignore_for_file for it

Copy link
Contributor

github-actions bot commented Jun 3, 2024

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 github-actions bot locked as resolved and limited conversation to collaborators Jun 3, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants