@@ -3500,15 +3500,7 @@ impl fmt::Display for Statement {
3500
3500
write ! ( f, " PARTITION BY {partition_by}" ) ?;
3501
3501
}
3502
3502
if let Some ( cluster_by) = cluster_by. as_ref ( ) {
3503
- write ! ( f, " CLUSTER BY " ) ?;
3504
- match cluster_by {
3505
- WrappedCollection :: NoWrapping ( cluster_by) => {
3506
- write ! ( f, "{}" , display_comma_separated( cluster_by. as_slice( ) ) ) ?;
3507
- }
3508
- WrappedCollection :: Parentheses ( cluster_by) => {
3509
- write ! ( f, "({})" , display_comma_separated( cluster_by. as_slice( ) ) ) ?;
3510
- }
3511
- }
3503
+ write ! ( f, " CLUSTER BY {cluster_by}" ) ?;
3512
3504
}
3513
3505
if let Some ( options) = options. as_ref ( ) {
3514
3506
write ! (
@@ -6533,15 +6525,46 @@ impl Display for CommentDef {
6533
6525
}
6534
6526
}
6535
6527
6536
- /// Helper to indicate if a collection should be wrapped by a symbol when displaying
6528
+ /// Helper to indicate if a collection should be wrapped by a symbol in the display form
6529
+ ///
6530
+ /// [`Display`] is implemented for every [Vec<T>] where `T: Display`.
6531
+ /// The string output is a comma separated list for the vec items
6532
+ ///
6533
+ /// # Examples
6534
+ /// ```
6535
+ /// # use sqlparser::ast::WrappedCollection;
6536
+ /// let items = WrappedCollection::Parentheses(vec!["one", "two", "three"]);
6537
+ /// assert_eq!("(one, two, three)", items.to_string());
6538
+ ///
6539
+ /// let items = WrappedCollection::NoWrapping(vec!["one", "two", "three"]);
6540
+ /// assert_eq!("one, two, three", items.to_string());
6541
+ /// ```
6537
6542
#[ derive( Debug , Clone , PartialEq , PartialOrd , Eq , Ord , Hash ) ]
6538
6543
#[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
6539
6544
#[ cfg_attr( feature = "visitor" , derive( Visit , VisitMut ) ) ]
6540
6545
pub enum WrappedCollection < T > {
6546
+ /// Print the collection without wrapping symbols, as `item, item, item`
6541
6547
NoWrapping ( T ) ,
6548
+ /// Wraps the collection in Parentheses, as `(item, item, item)`
6542
6549
Parentheses ( T ) ,
6543
6550
}
6544
6551
6552
+ impl < T > Display for WrappedCollection < Vec < T > >
6553
+ where
6554
+ T : Display ,
6555
+ {
6556
+ fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
6557
+ match self {
6558
+ WrappedCollection :: NoWrapping ( inner) => {
6559
+ write ! ( f, "{}" , display_comma_separated( inner. as_slice( ) ) )
6560
+ }
6561
+ WrappedCollection :: Parentheses ( inner) => {
6562
+ write ! ( f, "({})" , display_comma_separated( inner. as_slice( ) ) )
6563
+ }
6564
+ }
6565
+ }
6566
+ }
6567
+
6545
6568
#[ cfg( test) ]
6546
6569
mod tests {
6547
6570
use super :: * ;
0 commit comments