1- use crate :: common_constants as cc;
1+ use crate :: common_constants:: { self as cc, Tabs } ;
22use crate :: constants:: * ;
33use crate :: formatters:: * ;
44use crate :: piksi_tools_constants:: * ;
@@ -25,6 +25,7 @@ use std::{
2525 hash:: Hash ,
2626 net:: TcpStream ,
2727 ops:: Deref ,
28+ str:: FromStr ,
2829 sync:: { mpsc:: Sender , Arc , Mutex } ,
2930 thread,
3031 thread:: JoinHandle ,
@@ -414,13 +415,9 @@ pub enum RealtimeDelay {
414415// NavBar Types.
415416// Enum wrapping around various Vel NED Message types.
416417#[ derive( Debug ) ]
417- pub enum FlowControl {
418- None ,
419- Software ,
420- Hardware ,
421- }
418+ pub struct FlowControl ( SPFlowControl ) ;
422419
423- impl std :: str :: FromStr for FlowControl {
420+ impl FromStr for FlowControl {
424421 type Err = String ;
425422
426423 /// Convert flow control string slice to expected serialport FlowControl variant.
@@ -430,9 +427,9 @@ impl std::str::FromStr for FlowControl {
430427 /// - `sat_str`: The signal code.
431428 fn from_str ( s : & str ) -> std:: result:: Result < Self , Self :: Err > {
432429 match s {
433- FLOW_CONTROL_NONE => Ok ( FlowControl :: None ) ,
434- FLOW_CONTROL_SOFTWARE => Ok ( FlowControl :: Software ) ,
435- FLOW_CONTROL_HARDWARE => Ok ( FlowControl :: Hardware ) ,
430+ FLOW_CONTROL_NONE => Ok ( FlowControl ( SPFlowControl :: None ) ) ,
431+ FLOW_CONTROL_SOFTWARE => Ok ( FlowControl ( SPFlowControl :: Software ) ) ,
432+ FLOW_CONTROL_HARDWARE => Ok ( FlowControl ( SPFlowControl :: Hardware ) ) ,
436433 _ => Err ( format ! (
437434 "Not a valid flow control option. Choose from [\" {}\" , \" {}\" , \" {}\" ]" ,
438435 FLOW_CONTROL_NONE , FLOW_CONTROL_SOFTWARE , FLOW_CONTROL_HARDWARE
@@ -442,13 +439,32 @@ impl std::str::FromStr for FlowControl {
442439}
443440
444441impl Deref for FlowControl {
442+
445443 type Target = SPFlowControl ;
444+
446445 fn deref ( & self ) -> & Self :: Target {
447- match self {
448- FlowControl :: None => & SPFlowControl :: None ,
449- FlowControl :: Software => & SPFlowControl :: Software ,
450- FlowControl :: Hardware => & SPFlowControl :: Hardware ,
451- }
446+ & self . 0
447+ }
448+ }
449+
450+ #[ derive( Debug ) ]
451+ pub struct CliTabs ( Tabs ) ;
452+
453+ impl Deref for CliTabs {
454+
455+ type Target = Tabs ;
456+
457+ fn deref ( & self ) -> & Self :: Target {
458+ & self . 0
459+ }
460+ }
461+
462+ impl FromStr for CliTabs {
463+ type Err = String ;
464+
465+ fn from_str ( s : & str ) -> std:: result:: Result < Self , Self :: Err > {
466+ // TODO: add custom error handling
467+ Ok ( CliTabs ( Tabs :: from_str ( s) . map_err ( |e| format ! ( "{}" , e) ) ?) )
452468 }
453469}
454470
0 commit comments