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

encode_to should return Result #136

Open
arkpar opened this issue Jul 22, 2019 · 2 comments
Open

encode_to should return Result #136

arkpar opened this issue Jul 22, 2019 · 2 comments
Labels
enhancement New feature or request

Comments

@arkpar
Copy link
Member

arkpar commented Jul 22, 2019

In case provided slice is not big enough it should return an error, rather than panic.

@arkpar arkpar added the enhancement New feature or request label Jul 22, 2019
@gui1117
Copy link
Contributor

gui1117 commented Jul 23, 2019

Some solutions:
1 - we make Output returning a result and add the method encode_to_vec in Encode trait so ppl can make use of a trait as an Output without having to call expect on the result.

2 - we generalize first solution by having Output and FailableOutput, and there is two method in Encode which are encode_to, and failable_encode_to (we should come up with better names) and encode_to as default implementation which calls failable_encode_to (because FailableOutput will be implemented for Output) and unwrap the result.

3 - same as 1 but we don't event introduce encode_to_vec, but then all current code that uses this method will have to expect the result with the proof: "Vec implementation of Output never returns error".

I would go for 1

@gui1117
Copy link
Contributor

gui1117 commented Jul 23, 2019

also note that currently Output is only implemented for Vec<u8> in no_std

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants