Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Add support for BoundedArray #22

Merged
merged 2 commits into from
Jan 22, 2025
Merged

Conversation

evyatark2
Copy link
Contributor

I couldn't figure out the best way to detect a BoundedArray since it is not a type but a type constructor.

The way I go about it is to check if the struct "looks like" one (has a buffer field) and then we take the length of the array of the buffer field and construct a BoundedArray(u8, array_len) and check if it is the same type.

@speed2exe
Copy link
Owner

speed2exe commented Jan 22, 2025

@evyatark2 That is less explicit and may not only strictly refers to std.BoundedArray, I'd prefer to use @typeName, and check if it starts with or contains std.BoundedArray.

@evyatark2
Copy link
Contributor Author

That was my initial approach.

Wouldn't @typeName return zig.BoundedArray if the user decides to use const zig = @import("std");

As for the strictly referring to BoundedArray it does do that but only on the line if (FieldType == std.BoundedArray(u8, array.len)) after we check initially that it is potentially it.

@speed2exe
Copy link
Owner

Oh, I see what you mean, I guess this is fine. I don't have issue with implementing this way.

@speed2exe speed2exe merged commit 7fa86ac into speed2exe:main Jan 22, 2025
2 checks passed
@evyatark2 evyatark2 deleted the bounded_array branch January 22, 2025 20:09
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants