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

support for ReadIndices::try_into_u16 #436

Open
ickk opened this issue Oct 2, 2024 · 0 comments
Open

support for ReadIndices::try_into_u16 #436

ickk opened this issue Oct 2, 2024 · 0 comments

Comments

@ickk
Copy link

ickk commented Oct 2, 2024

I wanted a casting iterator for ReadIndices that would try to cast indices into u16s rather than u32s. I've implemented this feature, but not totally sure if it's something you would want to merge: here it is https://gist.github.com/ickk/da6a34cb6d3b4199d865d854fc8be0c4

With the linked gist, it becomes possible to call ReadIndices::try_into_u16, which returns an Option<CastingIter<'_, u16>>. It checks the variant of ReadIndices only once, making this efficient.

Caveats: It is obviously possible to have u32 indices that are all <= u16::MAX but in this case try_into_u16 cannot know this ahead of time and returns None. This makes try_into_u16 less useful in practice - you would have to have a separate branch to additionally handle TryFrom<u32> if assets may contain u32 indices.

If you'd like for me to PR this anyway (perhaps with a better name?) I will be glad to do so

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

1 participant