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

[Bug] Vec<Box<XXX>> is not supported in enum. #1072

Closed
iota9star opened this issue Feb 20, 2023 · 14 comments
Closed

[Bug] Vec<Box<XXX>> is not supported in enum. #1072

iota9star opened this issue Feb 20, 2023 · 14 comments
Labels
bug Something isn't working

Comments

@iota9star
Copy link

Describe the bug

Dart code is generated well, but rust code is not generated correctly.

Codegen logs with RUST_LOG=debug environment variable

work fine.

To Reproduce

  • enum
#[derive(Debug)]
#[frb(dart_metadata = ("freezed",))]
pub enum Test {
    Nothing,
    Array(Vec<Box<Test>>),
}
  • api.rs
pub fn test() -> Test {
    Test::Nothing
}
  • bridge_generated.rs
impl support::IntoDart for Test {
    fn into_dart(self) -> support::DartAbi {
        match self {
            Self::Nothing => vec![0.into_dart()],
            Self::Array(field0) => vec![1.into_dart(), field0.into_dart()],
        }
        .into_dart()
    }
}

image

Expected behavior

No response

Generated binding code

No response

OS

No response

Version of flutter_rust_bridge_codegen

No response

Flutter info

No response

Version of clang++

No response

Version of ffigen

No response

Additional context

No response

@iota9star iota9star added the bug Something isn't working label Feb 20, 2023
@welcome
Copy link

welcome bot commented Feb 20, 2023

Hi! Thanks for opening your first issue here! 😄

@fzyzcjy
Copy link
Owner

fzyzcjy commented Feb 21, 2023

Hmm looks like a bug. Feel free to PR to fix it!

guess about the reason: Maybe we forget to run code generator on the type

@iota9star
Copy link
Author

@fzyzcjy Can you solve this issue?allo-isolate

@fzyzcjy
Copy link
Owner

fzyzcjy commented Feb 21, 2023

IMHO the bug is unrelated to allo-isolate

@iota9star
Copy link
Author

It seems that allo-isolate did not implement into_dart for vec<box> @fzyzcjy I don't know the specific implementation details of frb,Is there a plan to solve it?

@fzyzcjy
Copy link
Owner

fzyzcjy commented Feb 21, 2023

IIRC, many impl IntoDart for WhateverType are auto-generated by frb. You may check bridge_generated.rs etc to see that.

Is there a plan to solve it?

Feel free to PR to fix it! If you get stuck, just ping me :)

@fzyzcjy
Copy link
Owner

fzyzcjy commented Feb 21, 2023

Btw does Vec<Xxx> work, and does Box<Xxx> work?

And, is it possible to workaround it by using Vec<Xxx> without box

@iota9star
Copy link
Author

iota9star commented Feb 21, 2023

Btw does Vec work, and does Box work?

It works well

@iota9star
Copy link
Author

iota9star commented Feb 21, 2023

IIRC, many impl IntoDart for WhateverType are auto-generated by frb. You may check bridge_generated.rs etc to see that.

frb doesn't need to generate vec<box>, the following part is correct

impl support::IntoDart for Test {
    fn into_dart(self) -> support::DartAbi {
        match self {
            Self::Nothing => vec![0.into_dart()],
            Self::Array(field0) => vec![1.into_dart(), field0.into_dart()],
        }
        .into_dart()
    }
}

impl support::IntoDartExceptPrimitive for Test {}

@iota9star
Copy link
Author

what fk! vec<box> is missing
image

@fzyzcjy
Copy link
Owner

fzyzcjy commented Feb 21, 2023

I see, good observation! Then maybe it should be implemented there. For example, I guess adding a few lines such as

impl<T> IntoDart for Box<T>
where
    T: IntoDartExceptPrimitive + Sized,
{
    fn into_dart(self) -> DartCObject {
        (*self).into_dart()
    }
}

should work

@iota9star
Copy link
Author

@fzyzcjy Sorry, I didn't use Box correctly. https://rust-lang.github.io/rust-clippy/master/index.html#vec_box
After removing Box, it works well

@github-actions
Copy link
Contributor

github-actions bot commented Mar 7, 2023

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 Mar 7, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants