Skip to content

Generic Types and Comparison #95

Closed Answered by celinval
aa-luna asked this question in Q&A
Sep 27, 2024 · 1 comments · 2 replies
Discussion options

You must be logged in to vote

Yeah, I understand the problem. The implementation for some of the NonZero<T> methods only requires T: ZeroablePrimitive, which doesn't provide any method to inspect or compare the T value.

In that case, I believe we'll have to work on a byte basis. For example, in order to check if a value is zero, you could get the address of the value, and create a *const [u8] where the len of the slice is the size of T. Then, you assume that it is safe to read from this slice, and check if any of the bytes is different than zero.

The same idea can be applied to compare values using byte comparison.

Please let me know if that makes sense or if anyone has any other solution.

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@celinval
Comment options

@feliperodri
Comment options

Answer selected by aa-luna
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants