File tree Expand file tree Collapse file tree 1 file changed +8
-9
lines changed
sugondat-shim/src/cmd/query Expand file tree Collapse file tree 1 file changed +8
-9
lines changed Original file line number Diff line number Diff line change @@ -46,17 +46,16 @@ fn read_blob(path: &str) -> anyhow::Result<Vec<u8>> {
4646///
4747/// The integer is interpreted as little-endian.
4848fn read_namespace ( namespace : & str ) -> anyhow:: Result < sugondat_nmt:: Namespace > {
49- if namespace. starts_with ( "0x" ) {
50- let namespace = namespace. trim_start_matches ( "0x" ) ;
51- let namespace = hex:: decode ( namespace) ?;
49+ if let Some ( hex) = namespace. strip_prefix ( "0x" ) {
50+ let namespace = hex:: decode ( hex) ?;
5251 let namespace: [ u8 ; 4 ] = namespace. try_into ( ) . map_err ( |e : Vec < u8 > | {
5352 anyhow:: anyhow!( "namespace must be 4 bytes long, but was {}" , e. len( ) )
5453 } ) ?;
55- Ok ( sugondat_nmt:: Namespace :: from_raw_bytes ( namespace) )
56- } else {
57- let namespace_id = namespace
58- . parse :: < u32 > ( )
59- . with_context ( || format ! ( "cannot parse namespace id '{}'" , namespace) ) ?;
60- Ok ( sugondat_nmt:: Namespace :: with_namespace_id ( namespace_id) )
54+ return Ok ( sugondat_nmt:: Namespace :: from_raw_bytes ( namespace) ) ;
6155 }
56+
57+ let namespace_id = namespace
58+ . parse :: < u32 > ( )
59+ . with_context ( || format ! ( "cannot parse namespace id '{}'" , namespace) ) ?;
60+ Ok ( sugondat_nmt:: Namespace :: with_namespace_id ( namespace_id) )
6261}
You can’t perform that action at this time.
0 commit comments