@@ -34,29 +34,34 @@ fn format_1d_array<A, S, F>(
34
34
write ! ( f, "[" ) ?;
35
35
for ( j, index) in to_be_printed. into_iter ( ) . enumerate ( ) {
36
36
match index {
37
- Some ( i) => {
37
+ PrintableCell :: ElementIndex ( i) => {
38
38
format ( & view[ i] , f) ?;
39
39
if j != n_to_be_printed - 1 {
40
40
write ! ( f, ", " ) ?;
41
41
}
42
42
} ,
43
- None => write ! ( f, "..., " ) ?,
43
+ PrintableCell :: Ellipses => write ! ( f, "..., " ) ?,
44
44
}
45
45
}
46
46
write ! ( f, "]" ) ?;
47
47
Ok ( ( ) )
48
48
}
49
49
50
+ enum PrintableCell {
51
+ ElementIndex ( usize ) ,
52
+ Ellipses ,
53
+ }
54
+
50
55
// Returns what indexes should be printed for a certain axis.
51
- // If the axis is longer than 2 * limit, a `None ` is inserted
56
+ // If the axis is longer than 2 * limit, a `Ellipses ` is inserted
52
57
// where indexes are being omitted.
53
- fn to_be_printed ( length : usize , limit : usize ) -> Vec < Option < usize > > {
58
+ fn to_be_printed ( length : usize , limit : usize ) -> Vec < PrintableCell > {
54
59
if length <= 2 * limit {
55
- ( 0 ..length) . map ( |x| Some ( x) ) . collect ( )
60
+ ( 0 ..length) . map ( |x| PrintableCell :: ElementIndex ( x) ) . collect ( )
56
61
} else {
57
- let mut v: Vec < Option < usize > > = ( 0 ..limit) . map ( |x| Some ( x) ) . collect ( ) ;
58
- v. push ( None ) ;
59
- v. extend ( ( length-limit..length) . map ( |x| Some ( x) ) ) ;
62
+ let mut v: Vec < PrintableCell > = ( 0 ..limit) . map ( |x| PrintableCell :: ElementIndex ( x) ) . collect ( ) ;
63
+ v. push ( PrintableCell :: Ellipses ) ;
64
+ v. extend ( ( length-limit..length) . map ( |x| PrintableCell :: ElementIndex ( x) ) ) ;
60
65
v
61
66
}
62
67
}
96
101
write ! ( f, "[" ) ?;
97
102
for ( j, index) in to_be_printed. into_iter ( ) . enumerate ( ) {
98
103
match index {
99
- Some ( i) => {
104
+ PrintableCell :: ElementIndex ( i) => {
100
105
// Proceed recursively with the (n-1)-dimensional slice
101
106
format_array (
102
107
& view. index_axis ( Axis ( 0 ) , i) , f, format. clone ( ) , limit
@@ -107,7 +112,7 @@ where
107
112
write ! ( f, ",\n " ) ?
108
113
}
109
114
} ,
110
- None => write ! ( f, "...,\n " ) ?
115
+ PrintableCell :: Ellipses => write ! ( f, "...,\n " ) ?
111
116
}
112
117
}
113
118
write ! ( f, "]" ) ?;
0 commit comments