File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -207,7 +207,7 @@ impl TryFrom<&[u8]> for Cid {
207207 let version = Version :: try_from ( raw_version) ?;
208208
209209 let ( raw_codec, hash) = varint_decode:: u64 ( & remain) ?;
210- let codec = Codec :: from ( raw_codec) ?;
210+ let codec = Codec :: try_from ( raw_codec) ?;
211211
212212 let mh = MultihashRef :: from_slice ( hash) ?. to_owned ( ) ;
213213
Original file line number Diff line number Diff line change 1+ use std:: convert:: TryFrom ;
2+
13use crate :: error:: { Error , Result } ;
24
35macro_rules! build_codec_enum {
@@ -8,9 +10,11 @@ macro_rules! build_codec_enum {
810 $( #[ $attr] $codec, ) *
911 }
1012
11- impl Codec {
13+ impl TryFrom <u64 > for Codec {
14+ type Error = Error ;
15+
1216 /// Convert a number to the matching codec, or `Error` if unknown codec is matching.
13- pub fn from ( raw: u64 ) -> Result <Codec > {
17+ fn try_from ( raw: u64 ) -> Result <Codec > {
1418 match raw {
1519 $( $code => Ok ( Self :: $codec) , ) *
1620 _ => Err ( Error :: UnknownCodec ) ,
Original file line number Diff line number Diff line change @@ -26,7 +26,7 @@ impl Prefix {
2626 let version = Version :: try_from ( raw_version) ?;
2727
2828 let ( raw_codec, remain) = varint_decode:: u64 ( remain) ?;
29- let codec = Codec :: from ( raw_codec) ?;
29+ let codec = Codec :: try_from ( raw_codec) ?;
3030
3131 let ( raw_mh_type, remain) = varint_decode:: u64 ( remain) ?;
3232 let mh_type = match multihash:: Code :: from_u64 ( raw_mh_type) {
You can’t perform that action at this time.
0 commit comments