-
Notifications
You must be signed in to change notification settings - Fork 170
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
Trait lookup works on an array but not on a struct #5006
Comments
impl Serde<STRUCT_SERIALIZED_LEN> for Struct {
fn deserialize(_data: [Field; STRUCT_SERIALIZED_LEN]) -> Self {
zeroed()
}
}
fn main() {
let _: Struct = [].deserialize();
let _: Bytes32 = [1; 32].deserialize();
} The error here is because you're implementing the trait for the self type of I'm not sure why the compiler mentions the type as |
That was my bad as I've changed array length from 1 to 0 during the writing of this issue. Edited. But on the nature of the issue:
|
Also - looking at your trait definition: trait Serde<LEN> {
fn deserialize(_data: [Field; LEN]) -> Self;
} We're in the process of implementing arithmetic on numeric generics: #4958 which should hopefully greatly help here when implementing trait Serde {
let LEN: u64;
fn deserialize(_data: [Field; Self::LEN]) -> Self;
} Since you shouldn't be able to implement |
Aim
I want to have a trait and use it's methods consistently, but I can't call them when I implement by trait on a struct.
Expected Behavior
Here is the code:
For some reason - the second line in main is OK while the first one is a compilation error
Bug
To Reproduce
Project Impact
Nice-to-have
Impact Context
Makes traits harder to use - causes worse code quality and hurts maintainability
Workaround
Yes
Workaround Description
Use syntax like:
Struct::deserialize
Additional Context
No response
Installation Method
Binary (
noirup
default)Nargo Version
0.28.0
NoirJS Version
No response
Would you like to submit a PR for this Issue?
None
Support Needs
No response
The text was updated successfully, but these errors were encountered: