-
Notifications
You must be signed in to change notification settings - Fork 55
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
add new trait to encode values to bytes #274
base: main
Are you sure you want to change the base?
Conversation
4c13edb
to
98c1031
Compare
Hey @antonilol 👋 Thank you again for your help and PR. I am wondering if we could follow a little more #257 and provide a "writer" (maybe start with a Would it be possible to:
|
This is certainly possible, what I have in mind right now is a method that by default forwards to to_bytes, but can be optionally implemented if desired.
With
I sure can, with the original names (BytesEncode, EItem, bytes_encode)? |
No, with the
Yup, would be perfect. |
Do you maybe mean the |
bee195f
to
a5c96f1
Compare
In a5c96f1 I used Either (a generic 2 value enum) to return different error types without using dynamic dispatch ( A new Either like 2 value enum instead of Either will work too if the dependency is an issue. |
Thank you for that, but I would prefer we keep these PR changes only for trait improvement. So that it's easier to review as less code changes. I'm also not a huge fan of returning a
I was talking about the |
When accepting
Do you mean dynamically choosing to borrow or return an owned type? This is still possible: to implement the trait the return value ( |
Can you
In issue #257, we are talking about a |
Sure, done
Now I get it, thanks for the patience in explaining it :), added the method to the trait |
still lots of TODOs
… only Vec<u8>, use Either for the 2 different errors
…nt of returning written bytes amount
4536a2f
to
3519c51
Compare
still lots of TODOs
Pull Request
Related issues
#165, #257
What does this PR do?
Introduces a new trait that allows more efficient implementations of encoding values to bytes by allowing users to return any
AsRef<[u8]> + Into<Vec<u8>>
type, possibly borrowed.TODOs
dyn std::error::Error
(Make the error returned by the BytesDecode/BytesEncode trait customizable #166 uses a generic Error type, seems like the best solution)