@@ -56,6 +56,14 @@ pub trait Pickable: Clone {
5656 fn column_constraints ( max_widths : & [ usize ] ) -> Vec < Constraint > ;
5757}
5858
59+ trait WrappedPickable : Pickable {
60+ type Inner ;
61+
62+ fn from_inner ( inner : Self :: Inner ) -> Self ;
63+
64+ fn into_inner ( self ) -> Self :: Inner ;
65+ }
66+
5967/// Configuration options for the generic picker UI.
6068#[ derive( Debug , Clone , Copy , Default ) ]
6169pub struct PickerOpts {
@@ -614,9 +622,7 @@ pub fn pick_container(
614622 opts : PickerOpts ,
615623 on_delete : Option < & mut dyn FnMut ( & ContainerItem ) > ,
616624) -> Result < Option < crate :: container:: Container > > {
617- let items: Vec < ContainerItem > = containers. into_iter ( ) . map ( ContainerItem ) . collect ( ) ;
618- let selected = pick ( items, opts, on_delete) ?;
619- Ok ( selected. map ( |item| item. 0 ) )
625+ pick_wrapped :: < ContainerItem > ( containers, opts, on_delete)
620626}
621627
622628/// Launches a picker for stored devcontainer configs.
@@ -625,22 +631,28 @@ pub fn pick_config(
625631 opts : PickerOpts ,
626632 on_delete : Option < & mut dyn FnMut ( & ConfigItem ) > ,
627633) -> Result < Option < crate :: config_store:: ConfigEntry > > {
628- let items: Vec < ConfigItem > = configs. into_iter ( ) . map ( ConfigItem ) . collect ( ) ;
629- let selected = pick ( items, opts, on_delete) ?;
630- Ok ( selected. map ( |item| item. 0 ) )
634+ pick_wrapped :: < ConfigItem > ( configs, opts, on_delete)
631635}
632636
633637/// Launches a picker for devcontainer selection.
634638pub fn pick_devcontainer (
635639 dev_containers : Vec < crate :: workspace:: DevContainer > ,
636640) -> Result < Option < crate :: workspace:: DevContainer > > {
637- let items: Vec < DevContainerItem > = dev_containers. into_iter ( ) . map ( DevContainerItem ) . collect ( ) ;
638641 let opts = PickerOpts {
639642 hide_instructions : false ,
640643 hide_info : false ,
641644 } ;
642- let selected = pick ( items, opts, None ) ?;
643- Ok ( selected. map ( |item| item. 0 ) )
645+ pick_wrapped :: < DevContainerItem > ( dev_containers, opts, None )
646+ }
647+
648+ fn pick_wrapped < T : WrappedPickable > (
649+ values : Vec < T :: Inner > ,
650+ opts : PickerOpts ,
651+ on_delete : Option < & mut dyn FnMut ( & T ) > ,
652+ ) -> Result < Option < T :: Inner > > {
653+ let items = values. into_iter ( ) . map ( T :: from_inner) . collect ( ) ;
654+ let selected = pick ( items, opts, on_delete) ?;
655+ Ok ( selected. map ( T :: into_inner) )
644656}
645657
646658fn add_num_opt ( o1 : Option < u32 > , o2 : Option < u32 > ) -> Option < u32 > {
0 commit comments