44//!
55//! [`TypeDef`]: crate::extension::TypeDef
66
7+ use itertools:: Itertools ;
78#[ cfg( test) ]
89use proptest_derive:: Arbitrary ;
910use std:: num:: NonZeroU64 ;
@@ -19,7 +20,7 @@ use crate::extension::SignatureError;
1920#[ derive(
2021 Clone , Debug , PartialEq , Eq , Hash , derive_more:: Display , serde:: Deserialize , serde:: Serialize ,
2122) ]
22- #[ display( "{}" , " _0.map(|i|i.to_string()).unwrap_or(\" - \ " .to_string())" ) ]
23+ #[ display( "{}" , _0. map( |i|i. to_string( ) ) . unwrap_or( "- ". to_string( ) ) ) ]
2324#[ cfg_attr( test, derive( Arbitrary ) ) ]
2425pub struct UpperBound ( Option < NonZeroU64 > ) ;
2526impl UpperBound {
@@ -56,11 +57,19 @@ impl UpperBound {
5657#[ serde( tag = "tp" ) ]
5758pub enum TypeParam {
5859 /// Argument is a [TypeArg::Type].
60+ #[ display( "Type{}" , match b {
61+ TypeBound :: Any => "" . to_string( ) ,
62+ _ => format!( "[{b}]" )
63+ } ) ]
5964 Type {
6065 /// Bound for the type parameter.
6166 b : TypeBound ,
6267 } ,
6368 /// Argument is a [TypeArg::BoundedNat] that is less than the upper bound.
69+ #[ display( "{}" , match bound. value( ) {
70+ Some ( v) => format!( "BoundedNat[{v}]" ) ,
71+ None => "Nat" . to_string( )
72+ } ) ]
6473 BoundedNat {
6574 /// Upper bound for the Nat parameter.
6675 bound : UpperBound ,
@@ -69,12 +78,13 @@ pub enum TypeParam {
6978 String ,
7079 /// Argument is a [TypeArg::Sequence]. A list of indeterminate size containing
7180 /// parameters all of the (same) specified element type.
81+ #[ display( "List[{param}]" ) ]
7282 List {
7383 /// The [TypeParam] describing each element of the list.
7484 param : Box < TypeParam > ,
7585 } ,
7686 /// Argument is a [TypeArg::Sequence]. A tuple of parameters.
77- #[ display( "Tuple({}) " , " params.iter().map(|t|t.to_string()).join(\ " , \" )" ) ]
87+ #[ display( "Tuple[{}] " , params. iter( ) . map( |t|t. to_string( ) ) . join( ", " ) ) ]
7888 Tuple {
7989 /// The [TypeParam]s contained in the tuple.
8090 params : Vec < TypeParam > ,
@@ -144,29 +154,31 @@ impl From<UpperBound> for TypeParam {
144154#[ serde( tag = "tya" ) ]
145155pub enum TypeArg {
146156 /// Where the (Type/Op)Def declares that an argument is a [TypeParam::Type]
157+ #[ display( "Type({ty})" ) ]
147158 Type {
148- # [ allow ( missing_docs ) ]
159+ /// The concrete type for the parameter.
149160 ty : Type ,
150161 } ,
151162 /// Instance of [TypeParam::BoundedNat]. 64-bit unsigned integer.
163+ #[ display( "{n}" ) ]
152164 BoundedNat {
153- # [ allow ( missing_docs ) ]
165+ /// The integer value for the parameter.
154166 n : u64 ,
155167 } ,
156168 ///Instance of [TypeParam::String]. UTF-8 encoded string argument.
157169 #[ display( "\" {arg}\" " ) ]
158170 String {
159- # [ allow ( missing_docs ) ]
171+ /// The string value for the parameter.
160172 arg : String ,
161173 } ,
162174 /// Instance of [TypeParam::List] or [TypeParam::Tuple], defined by a
163175 /// sequence of elements.
164- #[ display( "Sequence ({})" , {
176+ #[ display( "({})" , {
165177 use itertools:: Itertools as _;
166178 elems. iter( ) . map( |t|t. to_string( ) ) . join( "," )
167179 } ) ]
168180 Sequence {
169- # [ allow ( missing_docs ) ]
181+ /// List of element types
170182 elems : Vec < TypeArg > ,
171183 } ,
172184 /// Instance of [TypeParam::Extensions], providing the extension ids.
@@ -181,6 +193,7 @@ pub enum TypeArg {
181193 /// Variable (used in type schemes or inside polymorphic functions),
182194 /// but not a [TypeArg::Type] (not even a row variable i.e. [TypeParam::List] of type)
183195 /// nor [TypeArg::Extensions] - see [TypeArg::new_var_use]
196+ #[ display( "{}" , v) ]
184197 Variable {
185198 #[ allow( missing_docs) ]
186199 #[ serde( flatten) ]
@@ -235,7 +248,7 @@ impl From<ExtensionSet> for TypeArg {
235248#[ derive(
236249 Clone , Debug , PartialEq , Eq , Hash , serde:: Deserialize , serde:: Serialize , derive_more:: Display ,
237250) ]
238- #[ display( "TypeArgVariable( {idx}) " ) ]
251+ #[ display( "var# {idx}" ) ]
239252pub struct TypeArgVariable {
240253 idx : usize ,
241254 cached_decl : TypeParam ,
0 commit comments