@@ -56,6 +56,16 @@ impl From<Type> for ExpectedType {
5656 }
5757}
5858
59+ impl std:: fmt:: Display for ExpectedType {
60+ fn fmt ( & self , f : & mut Formatter < ' _ > ) -> fmt:: Result {
61+ match self {
62+ ExpectedType :: Array => write ! ( f, "Array<_>" ) ,
63+ ExpectedType :: Map => write ! ( f, "Map<_>" ) ,
64+ ExpectedType :: Type ( ty) => write ! ( f, "{}" , ty) ,
65+ }
66+ }
67+ }
68+
5969/// A list of expected types.
6070#[ derive( Default , Clone , PartialEq , Eq , Hash , PartialOrd , Ord ) ]
6171pub struct ExpectedTypeList ( BTreeSet < ExpectedType > ) ;
@@ -96,7 +106,25 @@ impl<T: Iterator<Item = ExpectedType>> From<T> for ExpectedTypeList {
96106
97107impl std:: fmt:: Display for ExpectedTypeList {
98108 fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
99- self . 0 . fmt ( f)
109+ match self . 0 . len ( ) {
110+ 0 => unreachable ! ( ) ,
111+ 1 => write ! ( f, "{}" , self . 0 . first( ) . unwrap( ) ) ,
112+ 2 => write ! (
113+ f,
114+ "{} or {}" ,
115+ self . 0 . first( ) . unwrap( ) ,
116+ self . 0 . last( ) . unwrap( )
117+ ) ,
118+ _ => {
119+ let mut iter = self . 0 . iter ( ) ;
120+ let first = iter. next ( ) . unwrap ( ) ;
121+ write ! ( f, "{{{}" , first) ?;
122+ for expected_type in iter {
123+ write ! ( f, ", {}" , expected_type) ?;
124+ }
125+ write ! ( f, "}}" )
126+ }
127+ }
100128 }
101129}
102130
@@ -399,8 +427,8 @@ impl std::fmt::Display for Type {
399427 Self :: Bytes => write ! ( f, "Bytes" ) ,
400428 Self :: Int => write ! ( f, "Int" ) ,
401429 Self :: Ip => write ! ( f, "Ip" ) ,
402- Self :: Array ( ty) => write ! ( f, "Array({}) " , Type :: from( * ty) ) ,
403- Self :: Map ( ty) => write ! ( f, "Map({}) " , Type :: from( * ty) ) ,
430+ Self :: Array ( ty) => write ! ( f, "Array<{}> " , Type :: from( * ty) ) ,
431+ Self :: Map ( ty) => write ! ( f, "Map<{}> " , Type :: from( * ty) ) ,
404432 }
405433 }
406434}
0 commit comments