@@ -480,23 +480,31 @@ impl dyn DynArray + '_ {
480480 write ! ( f, "{}" , if f. alternate( ) { "[\n " } else { "[" } ) ?;
481481 let sep = if * omit_comma_after_space { "," } else { ", " } ;
482482 let sep = if f. alternate ( ) { ",\n " } else { sep } ;
483- let limit = std:: cmp:: min ( self . len ( ) , f. precision ( ) . unwrap_or ( DISPLAY_LIMIT ) ) ;
483+ let limit = self . len ( ) . min ( f. precision ( ) . unwrap_or ( DISPLAY_LIMIT ) ) ;
484+ let is_truncated = self . len ( ) > limit;
484485 write ! (
485486 f,
486487 "{}" ,
487- ( 0 ..limit)
488+ ( 0 ..( limit - if is_truncated { 3 } else { 0 } ) )
488489 . map( |i| self
489490 . scalar_at( i)
490491 . map_or_else( |e| format!( "<error: {e}>" ) , |s| s. to_string( ) ) )
491492 . format( sep)
492493 ) ?;
493- let ellipsis = if self . len ( ) > limit {
494- format ! ( "{sep}..." )
495- } else {
496- "" . to_string ( )
497- } ;
494+ if is_truncated {
495+ write ! ( f, "{sep}...{sep}" ) ?;
496+ write ! (
497+ f,
498+ "{}" ,
499+ ( self . len( ) - 3 ..self . len( ) )
500+ . map( |i| self
501+ . scalar_at( i)
502+ . map_or_else( |e| format!( "<error: {e}>" ) , |s| s. to_string( ) ) )
503+ . format( sep)
504+ ) ?;
505+ }
498506 let closing_brace = if f. alternate ( ) { "\n ]" } else { "]" } ;
499- write ! ( f, "{ellipsis}{ closing_brace}" , )
507+ write ! ( f, "{closing_brace}" )
500508 }
501509 DisplayOptions :: TreeDisplay {
502510 buffers,
@@ -610,7 +618,7 @@ mod test {
610618 . into_array ( ) ;
611619 assert_eq ! (
612620 x. display_values( ) . to_string( ) ,
613- "[0i32, 1i32, 2i32, 3i32, 4i32, 5i32, 6i32, 7i32, 8i32, 9i32, 10i32, 11i32, 12i32, 13i32 , 14i32, 15i32, ... ]"
621+ "[0i32, 1i32, 2i32, 3i32, 4i32, 5i32, 6i32, 7i32, 8i32, 9i32, 10i32, 11i32, 12i32, ... , 14i32, 15i32, 16i32 ]"
614622 ) ;
615623 }
616624
0 commit comments