@@ -11,6 +11,18 @@ pub struct SubType {
11
11
pub composite_type : CompositeType ,
12
12
}
13
13
14
+ impl Encode for SubType {
15
+ fn encode ( & self , sink : & mut Vec < u8 > ) {
16
+ // We only need to emit a prefix byte before the actual composite type
17
+ // when either the type is not final or it has a declared super type.
18
+ if self . supertype_idx . is_some ( ) || !self . is_final {
19
+ sink. push ( if self . is_final { 0x4f } else { 0x50 } ) ;
20
+ self . supertype_idx . encode ( sink) ;
21
+ }
22
+ self . composite_type . encode ( sink) ;
23
+ }
24
+ }
25
+
14
26
#[ cfg( feature = "wasmparser" ) ]
15
27
impl From < wasmparser:: SubType > for SubType {
16
28
fn from ( sub_ty : wasmparser:: SubType ) -> Self {
@@ -510,14 +522,21 @@ impl TypeSection {
510
522
511
523
/// Define an explicit subtype in this type section.
512
524
pub fn subtype ( & mut self , ty : & SubType ) -> & mut Self {
513
- // We only need to emit a prefix byte before the actual composite type
514
- // when either the type is not final or it has a declared super type.
515
- if ty. supertype_idx . is_some ( ) || !ty. is_final {
516
- self . bytes . push ( if ty. is_final { 0x4f } else { 0x50 } ) ;
517
- ty. supertype_idx . encode ( & mut self . bytes ) ;
518
- }
525
+ ty. encode ( & mut self . bytes ) ;
526
+ self . num_added += 1 ;
527
+ self
528
+ }
519
529
520
- ty. composite_type . encode ( & mut self . bytes ) ;
530
+ /// Define an explicit recursion group in this type section.
531
+ pub fn rec < T > ( & mut self , types : T ) -> & mut Self
532
+ where
533
+ T : IntoIterator < Item = SubType > ,
534
+ T :: IntoIter : ExactSizeIterator ,
535
+ {
536
+ let types = types. into_iter ( ) ;
537
+ self . bytes . push ( 0x4e ) ;
538
+ types. len ( ) . encode ( & mut self . bytes ) ;
539
+ types. for_each ( |t| t. encode ( & mut self . bytes ) ) ;
521
540
self . num_added += 1 ;
522
541
self
523
542
}
0 commit comments