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

[u8; N] parsing panics due to missing space #34

Closed
geo-ant opened this issue Mar 1, 2024 · 1 comment
Closed

[u8; N] parsing panics due to missing space #34

geo-ant opened this issue Mar 1, 2024 · 1 comment

Comments

@geo-ant
Copy link

geo-ant commented Mar 1, 2024

Hi,

I tried using your crate like in the example in the documentation

const MY_RANDOM_BYTES: [u8; 32] = const_random!([u8; 32]);

That will panic with a message "invalid type". The underlying problem is in the parsing code in this line

byte_array: &str if byte_array.starts_with("[u8 ; ") && byte_array.ends_with(']')=> ...

Here you are sensitive to spaces and the formatting is problematic if someone has rustfmt enabled like I do. I could submit a PR to fix this, but rather than just patching that particular line I would want to use the syn crate to parse the tokens correctly. I don't know if you would want this dependency though, so I thought I'd ask. Your code works when I use

#[rustfmt::skip]
const MY_RANDOM_BYTES: [u8; 32] = const_random!([u8 ; 32]);

which seems a bit silly :)

@dtolnay
Copy link
Contributor

dtolnay commented Mar 1, 2024

This will be fixed by #33.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants