@@ -501,13 +501,9 @@ fn apply_char_mapping(
501
501
control_char_index : SpecialCharacterIndices ,
502
502
new_val : & str ,
503
503
) -> Result < ( ) , ControlCharMappingError > {
504
- match string_to_control_char ( new_val) {
505
- Ok ( val) => {
506
- termios. control_chars [ control_char_index as usize ] = val;
507
- Ok ( ( ) )
508
- }
509
- Err ( e) => Err ( e) ,
510
- }
504
+ string_to_control_char ( new_val) . map ( |val| {
505
+ termios. control_chars [ control_char_index as usize ] = val;
506
+ } )
511
507
}
512
508
513
509
// GNU stty defines some valid values for the control character mappings
@@ -518,21 +514,20 @@ fn apply_char_mapping(
518
514
// c. decimal, no prefix
519
515
// 3. Disabling the control character: '^-' or 'undef'
520
516
//
521
- // This function returns the ascii value of valid control chars, or None if the input is invalid
517
+ // This function returns the ascii value of valid control chars, or ControlCharMappingError if invalid
522
518
fn string_to_control_char ( s : & str ) -> Result < u8 , ControlCharMappingError > {
523
519
if s == "undef" || s == "^-" {
524
520
return Ok ( 0 ) ;
525
521
}
526
522
527
523
// try to parse integer (hex, octal, or decimal)
528
- let mut ascii_num: Option < u32 > = None ;
529
- if let Some ( hex) = s. strip_prefix ( "0x" ) {
530
- ascii_num = u32:: from_str_radix ( hex, 16 ) . ok ( ) ;
524
+ let ascii_num = if let Some ( hex) = s. strip_prefix ( "0x" ) {
525
+ u32:: from_str_radix ( hex, 16 ) . ok ( )
531
526
} else if let Some ( octal) = s. strip_prefix ( "0" ) {
532
- ascii_num = u32:: from_str_radix ( octal, 8 ) . ok ( ) ;
533
- } else if let Ok ( decimal ) = s . parse :: < u32 > ( ) {
534
- ascii_num = Some ( decimal ) ;
535
- }
527
+ u32:: from_str_radix ( octal, 8 ) . ok ( )
528
+ } else {
529
+ s . parse :: < u32 > ( ) . ok ( )
530
+ } ;
536
531
537
532
if let Some ( val) = ascii_num {
538
533
if val > 255 {
0 commit comments