@@ -6,15 +6,13 @@ extern crate alloc;
66use core:: alloc:: Layout ;
77
88use alloc_cortex_m:: CortexMHeap ;
9- use bech32:: { self , FromBase32 , Hrp , ToBase32 , Variant } ;
9+ use bech32:: { Bech32m , Hrp } ;
1010use cortex_m:: asm;
1111use cortex_m_rt:: entry;
1212use cortex_m_semihosting:: { debug, hprintln} ;
1313use panic_halt as _;
1414
1515use self :: alloc:: string:: ToString ;
16- use self :: alloc:: vec;
17- use self :: alloc:: vec:: Vec ;
1816
1917#[ global_allocator]
2018static ALLOCATOR : CortexMHeap = CortexMHeap :: empty ( ) ;
@@ -26,16 +24,18 @@ fn main() -> ! {
2624 // Initialize the allocator BEFORE you use it
2725 unsafe { ALLOCATOR . init ( cortex_m_rt:: heap_start ( ) as usize , HEAP_SIZE ) }
2826
29- let hrp = Hrp :: parse ( "bech32" ) . unwrap ( ) ;
30- let encoded = bech32:: encode ( hrp, vec ! [ 0x00 , 0x01 , 0x02 ] . to_base32 ( ) , Variant :: Bech32 ) . unwrap ( ) ;
31- test ( encoded == "bech321qqqsyrhqy2a" . to_string ( ) ) ;
27+ let data = [ 0x00u8 , 0x01 , 0x02 ] ;
28+ let hrp = Hrp :: parse ( "bech32" ) . expect ( "failed to parse hrp" ) ;
29+
30+ let encoded = bech32:: encode :: < Bech32m > ( hrp, & data) . expect ( "failed to encode" ) ;
31+ test ( encoded == "bech321qqqsyktsg0l" . to_string ( ) ) ;
3232
3333 hprintln ! ( "{}" , encoded) . unwrap ( ) ;
3434
35- let ( got_hrp, data, variant) = bech32:: decode ( & encoded) . unwrap ( ) ;
35+ let ( got_hrp, got_data) = bech32:: decode ( & encoded) . expect ( "failed to decode" ) ;
36+
3637 test ( got_hrp == hrp) ;
37- test ( Vec :: < u8 > :: from_base32 ( & data) . unwrap ( ) == vec ! [ 0x00 , 0x01 , 0x02 ] ) ;
38- test ( variant == Variant :: Bech32 ) ;
38+ test ( & got_data == & data) ;
3939
4040 debug:: exit ( debug:: EXIT_SUCCESS ) ;
4141
@@ -51,7 +51,7 @@ fn test(result: bool) {
5151// define what happens in an Out Of Memory (OOM) condition
5252#[ alloc_error_handler]
5353fn alloc_error ( layout : Layout ) -> ! {
54- hprintln ! ( "{:?}" , layout) ;
54+ hprintln ! ( "{:?}" , layout) . unwrap ( ) ;
5555 asm:: bkpt ( ) ;
5656
5757 loop { }
0 commit comments