Skip to content

support try_form? #119

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

Closed
bigdogs opened this issue Dec 25, 2021 · 3 comments · Fixed by #138
Closed

support try_form? #119

bigdogs opened this issue Dec 25, 2021 · 3 comments · Fixed by #138

Comments

@bigdogs
Copy link

bigdogs commented Dec 25, 2021

GenericArray::from_slice(&[u8) will panic if slice length is not match. It would be great to provide a Result version, e.g. (GenericArray::try_from_slice(&[u8) -> Result<Self, LengthNotMatch>)

@bigdogs
Copy link
Author

bigdogs commented Dec 25, 2021

and is there a method to get the array length from GenericArray? If try_from is not possible to support, I can check slice size before 'GenericArray::from_slice', But I didn't find any method for this.

@orthecreedence
Copy link

I do this outside the crate:

let arr: [u8; 32] = some_vec.try_from()?;
let genarr = GenericArray::from(arr);

@agostbiro
Copy link

There is also from_exact_iter that will return None if the sizes don't match.

@novacrazy novacrazy mentioned this issue Mar 28, 2023
Merged
2 tasks
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

Successfully merging a pull request may close this issue.

3 participants