`try_to_vec` never returns Result::Err()
lexfrl opened this issue · comments
Since the writer is vector, it will never return Result::Err()
. Since that we're able to not return an Result
. We use the interface quite often everywhere. Right now code is bloated with unnecessary unwrap()
s.
A Vec Write implementation:
https://doc.rust-lang.org/src/std/io/impls.rs.html#339
What do you think @nearmax ?
It returns error to allow custom types that have their own implementation of BorshSerialize to return error if something goes wrong. E.g. if type has inconsistent internal state that it refuses to serialize.
Closing as WAI.
E.g. if type has inconsistent internal state that it refuses to serialize.
In that case the interface should allow to specify a custom error type. But the method is not generic over Error, it returns io::Error
.
use std::io::{Error, Write};
fn try_to_vec(&self) -> Result<Vec<u8>, Error>
I suggest to add
fn to_vec(&self) -> Vec<u8>
And just deprecate try_to_vec
to not break the current API.
In that case the interface should allow to specify a custom error type.
io::Error
is widely used by Rust serializers, it should be sufficient for custom-written serialization methods too.