-
Notifications
You must be signed in to change notification settings - Fork 5
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
Support for const
variable in array init
#2
Comments
Is there a rust bug associated with this? All the issues linked seem to be closed or archived. |
This increases the minimum supported Rust version to 1.51.0. I sadly had to introduce another unsafe statement, because: * `Default` is only implemented for array lengths up to 32 (rust-lang/rust#61415) * arr_macro doesn't support const generics (JoshMcguigan/arr_macro#2) * Direct initialization via [T; N] adds a trait bound BinRead: Copy
This increases the minimum supported Rust version to 1.51.0. I sadly had to introduce another unsafe statement, because: * `Default` is only implemented for array lengths up to 32 (rust-lang/rust#61415) * arr_macro doesn't support const generics (JoshMcguigan/arr_macro#2) * Direct initialization via [T; N] adds a trait bound `BinRead: Copy`
This increases the minimum supported Rust version to 1.51.0. I sadly had to introduce another unsafe statement, because: * `Default` is only implemented for array lengths up to 32 (rust-lang/rust#61415) * arr_macro doesn't support const generics (JoshMcguigan/arr_macro#2) * Direct initialization via [T; N] adds a trait bound `BinRead: Copy`
|
@JoshMcguigan what is a possible workaround? |
I ran into this while using const generics to specify an array size and trying to fill that array with None without T being Copy or Default. I solved it by using this snippet: let array: [Option<T>; N] = (0..N).map(|_| None).collect::<Vec<_>>().try_into().ok().unwrap(); The It is obviously not ideal but for my purposes a good enough workaround. |
Is there a plan to support constant generic? |
Currently,
arr_macro
does not supportconst
variables in array initialization as shown below. This is because the macro needs to know the exact value ofSIZE
, but the compiler expands macros before doing name resolution.See additional details at dtolnay/syn#101
The text was updated successfully, but these errors were encountered: