@@ -548,16 +548,6 @@ impl SubType {
548
548
}
549
549
}
550
550
551
- /// Represents a composite type in a WebAssembly module.
552
- #[ derive( Debug , Clone , Hash , PartialEq , Eq , PartialOrd , Ord ) ]
553
- pub struct CompositeType {
554
- /// The type defined inside the composite type.
555
- pub inner : CompositeInnerType ,
556
- /// Is the composite type shared? This is part of the
557
- /// shared-everything-threads proposal.
558
- pub shared : bool ,
559
- }
560
-
561
551
/// A [`CompositeType`] can contain one of these types.
562
552
#[ derive( Debug , Clone , Hash , PartialEq , Eq , PartialOrd , Ord ) ]
563
553
pub enum CompositeInnerType {
@@ -571,18 +561,33 @@ pub enum CompositeInnerType {
571
561
Cont ( ContType ) ,
572
562
}
573
563
564
+ impl fmt:: Display for CompositeInnerType {
565
+ fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
566
+ match self {
567
+ CompositeInnerType :: Func ( ty) => write ! ( f, "{ty}" ) ,
568
+ CompositeInnerType :: Array ( ty) => write ! ( f, "{ty}" ) ,
569
+ CompositeInnerType :: Struct ( ty) => write ! ( f, "{ty}" ) ,
570
+ CompositeInnerType :: Cont ( ty) => write ! ( f, "{ty}" ) ,
571
+ }
572
+ }
573
+ }
574
+
575
+ /// Represents a composite type in a WebAssembly module.
576
+ #[ derive( Debug , Clone , Hash , PartialEq , Eq , PartialOrd , Ord ) ]
577
+ pub struct CompositeType {
578
+ /// The type defined inside the composite type.
579
+ pub inner : CompositeInnerType ,
580
+ /// Is the composite type shared? This is part of the
581
+ /// shared-everything-threads proposal.
582
+ pub shared : bool ,
583
+ }
584
+
574
585
impl fmt:: Display for CompositeType {
575
586
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
576
- use CompositeInnerType :: * ;
577
587
if self . shared {
578
588
write ! ( f, "(shared " ) ?;
579
589
}
580
- match self . inner {
581
- Array ( _) => write ! ( f, "(array ...)" ) ,
582
- Func ( _) => write ! ( f, "(func ...)" ) ,
583
- Struct ( _) => write ! ( f, "(struct ...)" ) ,
584
- Cont ( _) => write ! ( f, "(cont ...)" ) ,
585
- } ?;
590
+ write ! ( f, "{}" , self . inner) ?;
586
591
if self . shared {
587
592
write ! ( f, ")" ) ?;
588
593
}
@@ -642,6 +647,28 @@ impl fmt::Debug for FuncType {
642
647
}
643
648
}
644
649
650
+ impl fmt:: Display for FuncType {
651
+ fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
652
+ write ! ( f, "(func" ) ?;
653
+ if self . params ( ) . len ( ) > 0 {
654
+ write ! ( f, " (param" ) ?;
655
+ for p in self . params ( ) {
656
+ write ! ( f, " {p}" ) ?;
657
+ }
658
+ write ! ( f, ")" ) ?;
659
+ }
660
+ if self . results ( ) . len ( ) > 0 {
661
+ write ! ( f, " (result" ) ?;
662
+ for p in self . results ( ) {
663
+ write ! ( f, " {p}" ) ?;
664
+ }
665
+ write ! ( f, ")" ) ?;
666
+ }
667
+ write ! ( f, ")" ) ?;
668
+ Ok ( ( ) )
669
+ }
670
+ }
671
+
645
672
impl FuncType {
646
673
/// Creates a new [`FuncType`] from the given `params` and `results`.
647
674
pub fn new < P , R > ( params : P , results : R ) -> Self
@@ -698,35 +725,18 @@ impl FuncType {
698
725
pub ( crate ) fn results_mut ( & mut self ) -> & mut [ ValType ] {
699
726
& mut self . params_results [ self . len_params ..]
700
727
}
701
-
702
- #[ cfg( all( feature = "validate" , feature = "component-model" ) ) ]
703
- pub ( crate ) fn desc ( & self ) -> String {
704
- use core:: fmt:: Write ;
705
-
706
- let mut s = String :: new ( ) ;
707
- s. push_str ( "[" ) ;
708
- for ( i, param) in self . params ( ) . iter ( ) . enumerate ( ) {
709
- if i > 0 {
710
- s. push_str ( " " ) ;
711
- }
712
- write ! ( s, "{param}" ) . unwrap ( ) ;
713
- }
714
- s. push_str ( "] -> [" ) ;
715
- for ( i, result) in self . results ( ) . iter ( ) . enumerate ( ) {
716
- if i > 0 {
717
- s. push_str ( " " ) ;
718
- }
719
- write ! ( s, "{result}" ) . unwrap ( ) ;
720
- }
721
- s. push_str ( "]" ) ;
722
- s
723
- }
724
728
}
725
729
726
730
/// Represents a type of an array in a WebAssembly module.
727
731
#[ derive( Debug , Copy , Clone , Eq , PartialEq , Ord , PartialOrd , Hash ) ]
728
732
pub struct ArrayType ( pub FieldType ) ;
729
733
734
+ impl fmt:: Display for ArrayType {
735
+ fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
736
+ write ! ( f, "(array {})" , self . 0 )
737
+ }
738
+ }
739
+
730
740
/// Represents a field type of an array or a struct.
731
741
#[ derive( Debug , Copy , Clone , Eq , PartialEq , Ord , PartialOrd , Hash ) ]
732
742
pub struct FieldType {
@@ -736,6 +746,16 @@ pub struct FieldType {
736
746
pub mutable : bool ,
737
747
}
738
748
749
+ impl fmt:: Display for FieldType {
750
+ fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
751
+ if self . mutable {
752
+ write ! ( f, "(mut {})" , self . element_type)
753
+ } else {
754
+ fmt:: Display :: fmt ( & self . element_type , f)
755
+ }
756
+ }
757
+ }
758
+
739
759
impl FieldType {
740
760
/// Maps any `UnpackedIndex` via the specified closure.
741
761
#[ cfg( feature = "validate" ) ]
@@ -798,10 +818,27 @@ pub struct StructType {
798
818
pub fields : Box < [ FieldType ] > ,
799
819
}
800
820
821
+ impl fmt:: Display for StructType {
822
+ fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
823
+ write ! ( f, "(struct" ) ?;
824
+ for field in self . fields . iter ( ) {
825
+ write ! ( f, " {field}" ) ?;
826
+ }
827
+ write ! ( f, ")" ) ?;
828
+ Ok ( ( ) )
829
+ }
830
+ }
831
+
801
832
/// Represents a type of a continuation in a WebAssembly module.
802
833
#[ derive( Debug , Clone , Eq , PartialEq , Ord , PartialOrd , Hash ) ]
803
834
pub struct ContType ( pub PackedIndex ) ;
804
835
836
+ impl fmt:: Display for ContType {
837
+ fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
838
+ write ! ( f, "(cont {})" , self . 0 )
839
+ }
840
+ }
841
+
805
842
impl ContType {
806
843
/// Maps any `UnpackedIndex` via the specified closure.
807
844
#[ cfg( feature = "validate" ) ]
0 commit comments