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

structs with const generics in them don't codegen proeprly #2529

Open
LLFourn opened this issue Feb 6, 2025 · 4 comments
Open

structs with const generics in them don't codegen proeprly #2529

LLFourn opened this issue Feb 6, 2025 · 4 comments
Labels
awaiting Waiting for responses, PR, further discussions, upstream release, etc bug Something isn't working

Comments

@LLFourn
Copy link
Contributor

LLFourn commented Feb 6, 2025

Describe the bug

structs with const generics in them don't parse or generate properly

Steps to reproduce

I change the default template simple.rs to:

#[flutter_rust_bridge::frb(sync)] // Synchronous mode for simplicity of the demo
pub fn greet(_name: String) -> Foo<32> {
    todo!()
}

#[flutter_rust_bridge::frb(init)]
pub fn init_app() {
    // Default utilities - feel free to customize
    flutter_rust_bridge::setup_default_user_utils();
}

#[derive(Clone, Copy, Debug)]
pub struct Foo<const N: usize> {
    data: [u8; N],
}

And then generate doesn't work

Logs

no entry found for key=MirStructIdent(NamespacedName { namespace: Namespace { joined_path: "crate::api::simple" }, name: "Foo" })
thread 'main' panicked at /home/llfourn/.cargo/registry/src/index.crates.io-6f17d22bba15001f/flutter_rust_bridge_codegen-2.7.1/src/library/codegen/ir/mir/ty/structure.rs:36:32:
no entry found for key=MirStructIdent(NamespacedName { namespace: Namespace { joined_path: "crate::api::simple" }, name: "Foo" })

Expected behavior

I would at the very worst expect it to ignore the type and output a warning.

Generated binding code

Stuff looks like this:


impl SseEncode for crate::api::simple::Foo {
    // Codec=Sse (Serialization based), see doc to use other codecs
    fn sse_encode(self, serializer: &mut flutter_rust_bridge::for_generated::SseSerializer) {}
}


^ it's missing the const generic

OS

No response

Version of flutter_rust_bridge_codegen

flutter_rust_bridge_codegen 2.7.1

Flutter info

Version of clang++

No response

Additional context

No response

@LLFourn LLFourn added the bug Something isn't working label Feb 6, 2025
Copy link

welcome bot commented Feb 6, 2025

Hi! Thanks for opening your first issue here! 😄

@fzyzcjy
Copy link
Owner

fzyzcjy commented Feb 6, 2025

Yes, generics is not yet supported (due to its high complexity). One way to handle it is to use macros to create structs without generics.

@fzyzcjy fzyzcjy added the awaiting Waiting for responses, PR, further discussions, upstream release, etc label Feb 6, 2025
@LLFourn
Copy link
Contributor Author

LLFourn commented Feb 7, 2025

Just as a note I wasn't specifically trying to use a const generics struct, it just happened to be in one library I added to rust_input. I tried doing:

/// flutter_rust_bridge:ignore

on that struct in the library but that didn't work.

@fzyzcjy
Copy link
Owner

fzyzcjy commented Feb 7, 2025

I see. What about ignore all functions that use that struct as well - does it work?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting Waiting for responses, PR, further discussions, upstream release, etc bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants