@@ -21,6 +21,7 @@ use crate::currentprocess::{
21
21
varsource:: VarSource ,
22
22
} ;
23
23
use crate :: dist:: dist:: { TargetTriple , ToolchainDesc } ;
24
+ use crate :: dist:: manifest:: ComponentStatus ;
24
25
use crate :: install:: UpdateStatus ;
25
26
use crate :: utils:: notifications as util_notifications;
26
27
use crate :: utils:: notify:: NotificationLevel ;
@@ -379,38 +380,35 @@ pub(crate) fn list_targets(
379
380
distributable : DistributableToolchain < ' _ > ,
380
381
installed_only : bool ,
381
382
) -> Result < utils:: ExitCode > {
382
- let mut t = process ( ) . stdout ( ) . terminal ( ) ;
383
- for component in distributable. components ( ) ? {
384
- if component. component . short_name_in_manifest ( ) == "rust-std" {
385
- let target = component
386
- . component
387
- . target
388
- . as_ref ( )
389
- . expect ( "rust-std should have a target" ) ;
390
- match ( component. available , component. installed , installed_only) {
391
- ( false , _, _) | ( _, false , true ) => continue ,
392
- ( true , true , false ) => {
393
- t. attr ( terminalsource:: Attr :: Bold ) ?;
394
- writeln ! ( t. lock( ) , "{target} (installed)" ) ?;
395
- t. reset ( ) ?;
396
- }
397
- ( true , _, false ) | ( _, true , true ) => {
398
- writeln ! ( t. lock( ) , "{target}" ) ?;
399
- }
400
- }
401
- }
402
- }
403
-
404
- Ok ( utils:: ExitCode ( 0 ) )
383
+ list_items (
384
+ distributable,
385
+ |c| {
386
+ ( c. component . short_name_in_manifest ( ) == "rust-std" ) . then ( || {
387
+ c. component
388
+ . target
389
+ . as_deref ( )
390
+ . expect ( "rust-std should have a target" )
391
+ } )
392
+ } ,
393
+ installed_only,
394
+ )
405
395
}
406
396
407
397
pub ( crate ) fn list_components (
408
398
distributable : DistributableToolchain < ' _ > ,
409
399
installed_only : bool ,
400
+ ) -> Result < utils:: ExitCode > {
401
+ list_items ( distributable, |c| Some ( & c. name ) , installed_only)
402
+ }
403
+
404
+ fn list_items (
405
+ distributable : DistributableToolchain < ' _ > ,
406
+ f : impl Fn ( & ComponentStatus ) -> Option < & str > ,
407
+ installed_only : bool ,
410
408
) -> Result < utils:: ExitCode > {
411
409
let mut t = process ( ) . stdout ( ) . terminal ( ) ;
412
410
for component in distributable. components ( ) ? {
413
- let name = component. name ;
411
+ let Some ( name) = f ( & component) else { continue } ;
414
412
match ( component. available , component. installed , installed_only) {
415
413
( false , _, _) | ( _, false , true ) => continue ,
416
414
( true , true , false ) => {
0 commit comments