@@ -50,7 +50,6 @@ use crate::INTERNAL_ERROR_MSG;
50
50
#[ derive( Default , Clone ) ]
51
51
pub struct Arg < ' help > {
52
52
pub ( crate ) id : Id ,
53
- name : & ' help str ,
54
53
pub ( crate ) help : Option < & ' help str > ,
55
54
pub ( crate ) long_help : Option < & ' help str > ,
56
55
pub ( crate ) action : Option < ArgAction > ,
@@ -102,18 +101,16 @@ impl<'help> Arg<'help> {
102
101
/// # ;
103
102
/// ```
104
103
/// [`Arg::action(ArgAction::Set)`]: Arg::action()
105
- pub fn new ( id : impl Into < & ' help str > ) -> Self {
104
+ pub fn new ( id : impl Into < Id > ) -> Self {
106
105
Arg :: default ( ) . id ( id)
107
106
}
108
107
109
108
/// Set the identifier used for referencing this argument in the clap API.
110
109
///
111
110
/// See [`Arg::new`] for more details.
112
111
#[ must_use]
113
- pub fn id ( mut self , id : impl Into < & ' help str > ) -> Self {
114
- let id = id. into ( ) ;
115
- self . id = Id :: from ( id) ;
116
- self . name = id;
112
+ pub fn id ( mut self , id : impl Into < Id > ) -> Self {
113
+ self . id = id. into ( ) ;
117
114
self
118
115
}
119
116
@@ -660,9 +657,8 @@ impl<'help> Arg<'help> {
660
657
/// [Conflicting]: Arg::conflicts_with()
661
658
/// [override]: Arg::overrides_with()
662
659
#[ must_use]
663
- pub fn requires ( mut self , arg_id : impl Into < & ' help str > ) -> Self {
664
- self . requires
665
- . push ( ( ArgPredicate :: IsPresent , arg_id. into ( ) . into ( ) ) ) ;
660
+ pub fn requires ( mut self , arg_id : impl Into < Id > ) -> Self {
661
+ self . requires . push ( ( ArgPredicate :: IsPresent , arg_id. into ( ) ) ) ;
666
662
self
667
663
}
668
664
@@ -2443,8 +2439,8 @@ impl<'help> Arg<'help> {
2443
2439
///
2444
2440
/// [`ArgGroup`]: crate::ArgGroup
2445
2441
#[ must_use]
2446
- pub fn group ( mut self , group_id : impl Into < & ' help str > ) -> Self {
2447
- self . groups . push ( group_id. into ( ) . into ( ) ) ;
2442
+ pub fn group ( mut self , group_id : impl Into < Id > ) -> Self {
2443
+ self . groups . push ( group_id. into ( ) ) ;
2448
2444
self
2449
2445
}
2450
2446
@@ -2484,9 +2480,8 @@ impl<'help> Arg<'help> {
2484
2480
///
2485
2481
/// [`ArgGroup`]: crate::ArgGroup
2486
2482
#[ must_use]
2487
- pub fn groups ( mut self , group_ids : impl IntoIterator < Item = impl Into < & ' help str > > ) -> Self {
2488
- self . groups
2489
- . extend ( group_ids. into_iter ( ) . map ( |n| n. into ( ) . into ( ) ) ) ;
2483
+ pub fn groups ( mut self , group_ids : impl IntoIterator < Item = impl Into < Id > > ) -> Self {
2484
+ self . groups . extend ( group_ids. into_iter ( ) . map ( Into :: into) ) ;
2490
2485
self
2491
2486
}
2492
2487
@@ -2605,7 +2600,7 @@ impl<'help> Arg<'help> {
2605
2600
#[ must_use]
2606
2601
pub fn default_value_if (
2607
2602
self ,
2608
- arg_id : impl Into < & ' help str > ,
2603
+ arg_id : impl Into < Id > ,
2609
2604
val : Option < & ' help str > ,
2610
2605
default : Option < & ' help str > ,
2611
2606
) -> Self {
@@ -2620,12 +2615,12 @@ impl<'help> Arg<'help> {
2620
2615
#[ must_use]
2621
2616
pub fn default_value_if_os (
2622
2617
mut self ,
2623
- arg_id : impl Into < & ' help str > ,
2618
+ arg_id : impl Into < Id > ,
2624
2619
val : Option < & ' help OsStr > ,
2625
2620
default : Option < & ' help OsStr > ,
2626
2621
) -> Self {
2627
2622
self . default_vals_ifs
2628
- . push ( ( arg_id. into ( ) . into ( ) , val. into ( ) , default) ) ;
2623
+ . push ( ( arg_id. into ( ) , val. into ( ) , default) ) ;
2629
2624
self
2630
2625
}
2631
2626
@@ -2712,13 +2707,7 @@ impl<'help> Arg<'help> {
2712
2707
#[ must_use]
2713
2708
pub fn default_value_ifs (
2714
2709
mut self ,
2715
- ifs : impl IntoIterator <
2716
- Item = (
2717
- impl Into < & ' help str > ,
2718
- Option < & ' help str > ,
2719
- Option < & ' help str > ,
2720
- ) ,
2721
- > ,
2710
+ ifs : impl IntoIterator < Item = ( impl Into < Id > , Option < & ' help str > , Option < & ' help str > ) > ,
2722
2711
) -> Self {
2723
2712
for ( arg, val, default) in ifs {
2724
2713
self = self . default_value_if_os ( arg, val. map ( OsStr :: new) , default. map ( OsStr :: new) ) ;
@@ -2734,13 +2723,7 @@ impl<'help> Arg<'help> {
2734
2723
#[ must_use]
2735
2724
pub fn default_value_ifs_os (
2736
2725
mut self ,
2737
- ifs : impl IntoIterator <
2738
- Item = (
2739
- impl Into < & ' help str > ,
2740
- Option < & ' help OsStr > ,
2741
- Option < & ' help OsStr > ,
2742
- ) ,
2743
- > ,
2726
+ ifs : impl IntoIterator < Item = ( impl Into < Id > , Option < & ' help OsStr > , Option < & ' help OsStr > ) > ,
2744
2727
) -> Self {
2745
2728
for ( arg, val, default) in ifs {
2746
2729
self = self . default_value_if_os ( arg. into ( ) , val, default) ;
@@ -2802,8 +2785,8 @@ impl<'help> Arg<'help> {
2802
2785
/// ```
2803
2786
/// [required]: Arg::required()
2804
2787
#[ must_use]
2805
- pub fn required_unless_present ( mut self , arg_id : impl Into < & ' help str > ) -> Self {
2806
- self . r_unless . push ( arg_id. into ( ) . into ( ) ) ;
2788
+ pub fn required_unless_present ( mut self , arg_id : impl Into < Id > ) -> Self {
2789
+ self . r_unless . push ( arg_id. into ( ) ) ;
2807
2790
self
2808
2791
}
2809
2792
@@ -2877,10 +2860,9 @@ impl<'help> Arg<'help> {
2877
2860
#[ must_use]
2878
2861
pub fn required_unless_present_all (
2879
2862
mut self ,
2880
- names : impl IntoIterator < Item = impl Into < & ' help str > > ,
2863
+ names : impl IntoIterator < Item = impl Into < Id > > ,
2881
2864
) -> Self {
2882
- self . r_unless_all
2883
- . extend ( names. into_iter ( ) . map ( |n| n. into ( ) . into ( ) ) ) ;
2865
+ self . r_unless_all . extend ( names. into_iter ( ) . map ( Into :: into) ) ;
2884
2866
self
2885
2867
}
2886
2868
@@ -2956,10 +2938,9 @@ impl<'help> Arg<'help> {
2956
2938
#[ must_use]
2957
2939
pub fn required_unless_present_any (
2958
2940
mut self ,
2959
- names : impl IntoIterator < Item = impl Into < & ' help str > > ,
2941
+ names : impl IntoIterator < Item = impl Into < Id > > ,
2960
2942
) -> Self {
2961
- self . r_unless
2962
- . extend ( names. into_iter ( ) . map ( |n| n. into ( ) . into ( ) ) ) ;
2943
+ self . r_unless . extend ( names. into_iter ( ) . map ( Into :: into) ) ;
2963
2944
self
2964
2945
}
2965
2946
@@ -3043,8 +3024,8 @@ impl<'help> Arg<'help> {
3043
3024
/// [Conflicting]: Arg::conflicts_with()
3044
3025
/// [required]: Arg::required()
3045
3026
#[ must_use]
3046
- pub fn required_if_eq ( mut self , arg_id : impl Into < & ' help str > , val : & ' help str ) -> Self {
3047
- self . r_ifs . push ( ( arg_id. into ( ) . into ( ) , val) ) ;
3027
+ pub fn required_if_eq ( mut self , arg_id : impl Into < Id > , val : & ' help str ) -> Self {
3028
+ self . r_ifs . push ( ( arg_id. into ( ) , val) ) ;
3048
3029
self
3049
3030
}
3050
3031
@@ -3124,10 +3105,10 @@ impl<'help> Arg<'help> {
3124
3105
#[ must_use]
3125
3106
pub fn required_if_eq_any (
3126
3107
mut self ,
3127
- ifs : impl IntoIterator < Item = ( impl Into < & ' help str > , & ' help str ) > ,
3108
+ ifs : impl IntoIterator < Item = ( impl Into < Id > , & ' help str ) > ,
3128
3109
) -> Self {
3129
3110
self . r_ifs
3130
- . extend ( ifs. into_iter ( ) . map ( |( id, val) | ( id. into ( ) . into ( ) , val) ) ) ;
3111
+ . extend ( ifs. into_iter ( ) . map ( |( id, val) | ( id. into ( ) , val) ) ) ;
3131
3112
self
3132
3113
}
3133
3114
@@ -3205,10 +3186,10 @@ impl<'help> Arg<'help> {
3205
3186
#[ must_use]
3206
3187
pub fn required_if_eq_all (
3207
3188
mut self ,
3208
- ifs : impl IntoIterator < Item = ( impl Into < & ' help str > , & ' help str ) > ,
3189
+ ifs : impl IntoIterator < Item = ( impl Into < Id > , & ' help str ) > ,
3209
3190
) -> Self {
3210
3191
self . r_ifs_all
3211
- . extend ( ifs. into_iter ( ) . map ( |( id, val) | ( id. into ( ) . into ( ) , val) ) ) ;
3192
+ . extend ( ifs. into_iter ( ) . map ( |( id, val) | ( id. into ( ) , val) ) ) ;
3212
3193
self
3213
3194
}
3214
3195
@@ -3268,9 +3249,9 @@ impl<'help> Arg<'help> {
3268
3249
/// [Conflicting]: Arg::conflicts_with()
3269
3250
/// [override]: Arg::overrides_with()
3270
3251
#[ must_use]
3271
- pub fn requires_if ( mut self , val : & ' help str , arg_id : impl Into < & ' help str > ) -> Self {
3252
+ pub fn requires_if ( mut self , val : & ' help str , arg_id : impl Into < Id > ) -> Self {
3272
3253
self . requires
3273
- . push ( ( ArgPredicate :: Equals ( OsStr :: new ( val) ) , arg_id. into ( ) . into ( ) ) ) ;
3254
+ . push ( ( ArgPredicate :: Equals ( OsStr :: new ( val) ) , arg_id. into ( ) ) ) ;
3274
3255
self
3275
3256
}
3276
3257
@@ -3321,11 +3302,11 @@ impl<'help> Arg<'help> {
3321
3302
#[ must_use]
3322
3303
pub fn requires_ifs (
3323
3304
mut self ,
3324
- ifs : impl IntoIterator < Item = ( & ' help str , impl Into < & ' help str > ) > ,
3305
+ ifs : impl IntoIterator < Item = ( & ' help str , impl Into < Id > ) > ,
3325
3306
) -> Self {
3326
3307
self . requires . extend (
3327
3308
ifs. into_iter ( )
3328
- . map ( |( val, arg) | ( ArgPredicate :: Equals ( OsStr :: new ( val) ) , arg. into ( ) . into ( ) ) ) ,
3309
+ . map ( |( val, arg) | ( ArgPredicate :: Equals ( OsStr :: new ( val) ) , arg. into ( ) ) ) ,
3329
3310
) ;
3330
3311
self
3331
3312
}
@@ -3389,11 +3370,11 @@ impl<'help> Arg<'help> {
3389
3370
/// [Conflicting]: Arg::conflicts_with()
3390
3371
/// [override]: Arg::overrides_with()
3391
3372
#[ must_use]
3392
- pub fn requires_all ( mut self , names : impl IntoIterator < Item = impl Into < & ' help str > > ) -> Self {
3373
+ pub fn requires_all ( mut self , names : impl IntoIterator < Item = impl Into < Id > > ) -> Self {
3393
3374
self . requires . extend (
3394
3375
names
3395
3376
. into_iter ( )
3396
- . map ( |s| ( ArgPredicate :: IsPresent , s. into ( ) . into ( ) ) ) ,
3377
+ . map ( |s| ( ArgPredicate :: IsPresent , s. into ( ) ) ) ,
3397
3378
) ;
3398
3379
self
3399
3380
}
@@ -3443,8 +3424,8 @@ impl<'help> Arg<'help> {
3443
3424
/// [`Arg::conflicts_with_all(names)`]: Arg::conflicts_with_all()
3444
3425
/// [`Arg::exclusive(true)`]: Arg::exclusive()
3445
3426
#[ must_use]
3446
- pub fn conflicts_with ( mut self , arg_id : impl Into < & ' help str > ) -> Self {
3447
- self . blacklist . push ( arg_id. into ( ) . into ( ) ) ;
3427
+ pub fn conflicts_with ( mut self , arg_id : impl Into < Id > ) -> Self {
3428
+ self . blacklist . push ( arg_id. into ( ) ) ;
3448
3429
self
3449
3430
}
3450
3431
@@ -3493,12 +3474,8 @@ impl<'help> Arg<'help> {
3493
3474
/// [`Arg::conflicts_with`]: Arg::conflicts_with()
3494
3475
/// [`Arg::exclusive(true)`]: Arg::exclusive()
3495
3476
#[ must_use]
3496
- pub fn conflicts_with_all (
3497
- mut self ,
3498
- names : impl IntoIterator < Item = impl Into < & ' help str > > ,
3499
- ) -> Self {
3500
- self . blacklist
3501
- . extend ( names. into_iter ( ) . map ( |n| n. into ( ) . into ( ) ) ) ;
3477
+ pub fn conflicts_with_all ( mut self , names : impl IntoIterator < Item = impl Into < Id > > ) -> Self {
3478
+ self . blacklist . extend ( names. into_iter ( ) . map ( Into :: into) ) ;
3502
3479
self
3503
3480
}
3504
3481
@@ -3535,8 +3512,8 @@ impl<'help> Arg<'help> {
3535
3512
/// assert!(!*m.get_one::<bool>("flag").unwrap());
3536
3513
/// ```
3537
3514
#[ must_use]
3538
- pub fn overrides_with ( mut self , arg_id : impl Into < & ' help str > ) -> Self {
3539
- self . overrides . push ( arg_id. into ( ) . into ( ) ) ;
3515
+ pub fn overrides_with ( mut self , arg_id : impl Into < Id > ) -> Self {
3516
+ self . overrides . push ( arg_id. into ( ) ) ;
3540
3517
self
3541
3518
}
3542
3519
@@ -3571,12 +3548,8 @@ impl<'help> Arg<'help> {
3571
3548
/// assert!(!*m.get_one::<bool>("flag").unwrap());
3572
3549
/// ```
3573
3550
#[ must_use]
3574
- pub fn overrides_with_all (
3575
- mut self ,
3576
- names : impl IntoIterator < Item = impl Into < & ' help str > > ,
3577
- ) -> Self {
3578
- self . overrides
3579
- . extend ( names. into_iter ( ) . map ( |n| n. into ( ) . into ( ) ) ) ;
3551
+ pub fn overrides_with_all ( mut self , names : impl IntoIterator < Item = impl Into < Id > > ) -> Self {
3552
+ self . overrides . extend ( names. into_iter ( ) . map ( Into :: into) ) ;
3580
3553
self
3581
3554
}
3582
3555
}
@@ -3585,8 +3558,8 @@ impl<'help> Arg<'help> {
3585
3558
impl < ' help > Arg < ' help > {
3586
3559
/// Get the name of the argument
3587
3560
#[ inline]
3588
- pub fn get_id ( & self ) -> & ' help str {
3589
- self . name
3561
+ pub fn get_id ( & self ) -> & Id {
3562
+ & self . id
3590
3563
}
3591
3564
3592
3565
/// Get the help specified for this argument, if any
@@ -4017,7 +3990,7 @@ impl<'help> Arg<'help> {
4017
3990
}
4018
3991
} else {
4019
3992
debug ! ( "Arg::name_no_brackets: just name" ) ;
4020
- Cow :: Borrowed ( self . get_id ( ) )
3993
+ Cow :: Borrowed ( self . get_id ( ) . as_str ( ) )
4021
3994
}
4022
3995
}
4023
3996
@@ -4051,7 +4024,7 @@ impl<'help> PartialOrd for Arg<'help> {
4051
4024
4052
4025
impl < ' help > Ord for Arg < ' help > {
4053
4026
fn cmp ( & self , other : & Arg ) -> Ordering {
4054
- self . get_id ( ) . cmp ( other. get_id ( ) )
4027
+ self . id . cmp ( & other. id )
4055
4028
}
4056
4029
}
4057
4030
@@ -4110,7 +4083,6 @@ impl<'help> fmt::Debug for Arg<'help> {
4110
4083
#[ allow( unused_mut) ]
4111
4084
let mut ds = ds
4112
4085
. field ( "id" , & self . id )
4113
- . field ( "name" , & self . name )
4114
4086
. field ( "help" , & self . help )
4115
4087
. field ( "long_help" , & self . long_help )
4116
4088
. field ( "action" , & self . action )
@@ -4155,7 +4127,7 @@ pub(crate) fn render_arg_val(arg: &Arg) -> String {
4155
4127
4156
4128
let arg_name_storage;
4157
4129
let val_names = if arg. val_names . is_empty ( ) {
4158
- arg_name_storage = [ arg. get_id ( ) ] ;
4130
+ arg_name_storage = [ arg. get_id ( ) . as_str ( ) ] ;
4159
4131
& arg_name_storage
4160
4132
} else {
4161
4133
arg. val_names . as_slice ( )
0 commit comments