Description
This is a tracking issue for Implement TryFrom<Bytes>
for b256
.
The experimental feature flag for the issue is try_from_bytes_for_b256
.
Description
Currently, b256
implements From<Bytes>
which can cause data losses. We want to remove that implementation and replace it with TryFrom<Bytes>
which will return None
if the provided Bytes
cannot be safely converted to b256
.
Breaking Changes
Replace calls to from(bytes)/bytes.into()
with try_from(bytes)/bytes.try_into()
E.g., calls to from
:
let result = b256::from(some_bytes);
will become:
let result = b256::try_from(some_bytes).unwrap();
E.g., calls to into
:
let result: b256 = some_bytes.into();
will become:
let result: b256 = some_bytes.try_into().unwrap();
Calling unwrap()
assumes that the previous usage was always semantically valid. It is recommended to inspect all the previous usages of from/into
to ensure unwrap
ing is always safe, or to check for the Option
result of try_from/try_into
.