1919/// Simplify parsing of arguments
2020pub mod prelude {
2121 pub use crate :: Arg :: * ;
22- pub use crate :: OptionContextExt as _;
23- pub use crate :: ResultContextExt as _;
22+ pub use crate :: OptionLexErrorExt as _;
23+ pub use crate :: ResultLexErrorExt as _;
2424 pub use crate :: ValueExt as _;
2525}
2626
27- pub use lexarg_error:: ErrorContext ;
27+ pub use lexarg_error:: LexError ;
2828pub use lexarg_parser:: Arg ;
2929pub use lexarg_parser:: Parser ;
3030pub use lexarg_parser:: RawArgs ;
@@ -50,9 +50,9 @@ impl Error {
5050 }
5151}
5252
53- impl From < ErrorContext < ' _ > > for Error {
53+ impl From < LexError < ' _ > > for Error {
5454 #[ cold]
55- fn from ( error : ErrorContext < ' _ > ) -> Self {
55+ fn from ( error : LexError < ' _ > ) -> Self {
5656 Self :: msg ( error. to_string ( ) )
5757 }
5858}
@@ -72,32 +72,32 @@ impl std::fmt::Display for Error {
7272/// Extensions for parsing [`Arg::Value`]
7373pub trait ValueExt < ' a > {
7474 /// Convert [`Arg::Value`]
75- fn path ( self ) -> Result < & ' a std:: path:: Path , ErrorContext < ' a > > ;
75+ fn path ( self ) -> Result < & ' a std:: path:: Path , LexError < ' a > > ;
7676 /// Convert [`Arg::Value`] with a description of the intended format
77- fn string ( self , description : & str ) -> Result < & ' a str , ErrorContext < ' a > > ;
77+ fn string ( self , description : & str ) -> Result < & ' a str , LexError < ' a > > ;
7878 /// Ensure [`Arg::Value`] is from a closed set of values
79- fn one_of ( self , possible : & [ & str ] ) -> Result < & ' a str , ErrorContext < ' a > > ;
79+ fn one_of ( self , possible : & [ & str ] ) -> Result < & ' a str , LexError < ' a > > ;
8080 /// Parse [`Arg::Value`]
81- fn parse < T : std:: str:: FromStr > ( self ) -> Result < T , ErrorContext < ' a > >
81+ fn parse < T : std:: str:: FromStr > ( self ) -> Result < T , LexError < ' a > >
8282 where
8383 T :: Err : std:: fmt:: Display ;
8484 /// Custom conversion for [`Arg::Value`]
85- fn try_map < F , T , E > ( self , op : F ) -> Result < T , ErrorContext < ' a > >
85+ fn try_map < F , T , E > ( self , op : F ) -> Result < T , LexError < ' a > >
8686 where
8787 F : FnOnce ( & ' a std:: ffi:: OsStr ) -> Result < T , E > ,
8888 E : std:: fmt:: Display ;
8989}
9090
9191impl < ' a > ValueExt < ' a > for & ' a std:: ffi:: OsStr {
92- fn path ( self ) -> Result < & ' a std:: path:: Path , ErrorContext < ' a > > {
92+ fn path ( self ) -> Result < & ' a std:: path:: Path , LexError < ' a > > {
9393 Ok ( std:: path:: Path :: new ( self ) )
9494 }
95- fn string ( self , description : & str ) -> Result < & ' a str , ErrorContext < ' a > > {
95+ fn string ( self , description : & str ) -> Result < & ' a str , LexError < ' a > > {
9696 self . to_str ( ) . ok_or_else ( || {
97- ErrorContext :: msg ( format_args ! ( "invalid {description}" ) ) . unexpected ( Arg :: Value ( self ) )
97+ LexError :: msg ( format_args ! ( "invalid {description}" ) ) . unexpected ( Arg :: Value ( self ) )
9898 } )
9999 }
100- fn one_of ( self , possible : & [ & str ] ) -> Result < & ' a str , ErrorContext < ' a > > {
100+ fn one_of ( self , possible : & [ & str ] ) -> Result < & ' a str , LexError < ' a > > {
101101 self . to_str ( )
102102 . filter ( |v| possible. contains ( v) )
103103 . ok_or_else ( || {
@@ -108,43 +108,43 @@ impl<'a> ValueExt<'a> for &'a std::ffi::OsStr {
108108 use std:: fmt:: Write as _;
109109 let _ = write ! ( & mut error, ", `{possible}`" ) ;
110110 }
111- ErrorContext :: msg ( error)
111+ LexError :: msg ( error)
112112 } )
113113 }
114- fn parse < T : std:: str:: FromStr > ( self ) -> Result < T , ErrorContext < ' a > >
114+ fn parse < T : std:: str:: FromStr > ( self ) -> Result < T , LexError < ' a > >
115115 where
116116 T :: Err : std:: fmt:: Display ,
117117 {
118118 self . string ( std:: any:: type_name :: < T > ( ) ) ?
119119 . parse :: < T > ( )
120- . map_err ( |err| ErrorContext :: msg ( err) . unexpected ( Arg :: Value ( self ) ) )
120+ . map_err ( |err| LexError :: msg ( err) . unexpected ( Arg :: Value ( self ) ) )
121121 }
122- fn try_map < F , T , E > ( self , op : F ) -> Result < T , ErrorContext < ' a > >
122+ fn try_map < F , T , E > ( self , op : F ) -> Result < T , LexError < ' a > >
123123 where
124124 F : FnOnce ( & ' a std:: ffi:: OsStr ) -> Result < T , E > ,
125125 E : std:: fmt:: Display ,
126126 {
127- op ( self ) . map_err ( |err| ErrorContext :: msg ( err) . unexpected ( Arg :: Value ( self ) ) )
127+ op ( self ) . map_err ( |err| LexError :: msg ( err) . unexpected ( Arg :: Value ( self ) ) )
128128 }
129129}
130130
131- impl < ' a > ValueExt < ' a > for Result < & ' a std:: ffi:: OsStr , ErrorContext < ' a > > {
132- fn path ( self ) -> Result < & ' a std:: path:: Path , ErrorContext < ' a > > {
131+ impl < ' a > ValueExt < ' a > for Result < & ' a std:: ffi:: OsStr , LexError < ' a > > {
132+ fn path ( self ) -> Result < & ' a std:: path:: Path , LexError < ' a > > {
133133 self . and_then ( |os| os. path ( ) )
134134 }
135- fn string ( self , description : & str ) -> Result < & ' a str , ErrorContext < ' a > > {
135+ fn string ( self , description : & str ) -> Result < & ' a str , LexError < ' a > > {
136136 self . and_then ( |os| os. string ( description) )
137137 }
138- fn one_of ( self , possible : & [ & str ] ) -> Result < & ' a str , ErrorContext < ' a > > {
138+ fn one_of ( self , possible : & [ & str ] ) -> Result < & ' a str , LexError < ' a > > {
139139 self . and_then ( |os| os. one_of ( possible) )
140140 }
141- fn parse < T : std:: str:: FromStr > ( self ) -> Result < T , ErrorContext < ' a > >
141+ fn parse < T : std:: str:: FromStr > ( self ) -> Result < T , LexError < ' a > >
142142 where
143143 T :: Err : std:: fmt:: Display ,
144144 {
145145 self . and_then ( |os| os. parse ( ) )
146146 }
147- fn try_map < F , T , E > ( self , op : F ) -> Result < T , ErrorContext < ' a > >
147+ fn try_map < F , T , E > ( self , op : F ) -> Result < T , LexError < ' a > >
148148 where
149149 F : FnOnce ( & ' a std:: ffi:: OsStr ) -> Result < T , E > ,
150150 E : std:: fmt:: Display ,
@@ -153,33 +153,33 @@ impl<'a> ValueExt<'a> for Result<&'a std::ffi::OsStr, ErrorContext<'a>> {
153153 }
154154}
155155
156- /// Extensions for extending [`ErrorContext `]
157- pub trait ResultContextExt < ' a > {
156+ /// Extensions for extending [`LexError `]
157+ pub trait ResultLexErrorExt < ' a > {
158158 /// [`Arg`] the error occurred within
159159 fn within ( self , within : Arg < ' a > ) -> Self ;
160160}
161161
162- impl < ' a , T > ResultContextExt < ' a > for Result < T , ErrorContext < ' a > > {
162+ impl < ' a , T > ResultLexErrorExt < ' a > for Result < T , LexError < ' a > > {
163163 fn within ( self , within : Arg < ' a > ) -> Self {
164164 self . map_err ( |err| err. within ( within) )
165165 }
166166}
167167
168- /// Extensions for creating an [`ErrorContext `]
169- pub trait OptionContextExt < T > {
168+ /// Extensions for creating an [`LexError `]
169+ pub trait OptionLexErrorExt < T > {
170170 /// [`Arg`] that was expected
171171 ///
172172 /// For [`Arg::Value`], the contents are assumed to be a placeholder
173- fn ok_or_missing ( self , expected : Arg < ' static > ) -> Result < T , ErrorContext < ' static > > ;
173+ fn ok_or_missing ( self , expected : Arg < ' static > ) -> Result < T , LexError < ' static > > ;
174174}
175175
176- impl < T > OptionContextExt < T > for Option < T > {
177- fn ok_or_missing ( self , expected : Arg < ' static > ) -> Result < T , ErrorContext < ' static > > {
176+ impl < T > OptionLexErrorExt < T > for Option < T > {
177+ fn ok_or_missing ( self , expected : Arg < ' static > ) -> Result < T , LexError < ' static > > {
178178 self . ok_or_else ( || match expected {
179- Arg :: Short ( short) => ErrorContext :: msg ( format_args ! ( "missing required `-{short}`" ) ) ,
180- Arg :: Long ( long) => ErrorContext :: msg ( format_args ! ( "missing required `--{long}`" ) ) ,
181- Arg :: Escape ( escape) => ErrorContext :: msg ( format_args ! ( "missing required `{escape}`" ) ) ,
182- Arg :: Value ( value) | Arg :: Unexpected ( value) => ErrorContext :: msg ( format_args ! (
179+ Arg :: Short ( short) => LexError :: msg ( format_args ! ( "missing required `-{short}`" ) ) ,
180+ Arg :: Long ( long) => LexError :: msg ( format_args ! ( "missing required `--{long}`" ) ) ,
181+ Arg :: Escape ( escape) => LexError :: msg ( format_args ! ( "missing required `{escape}`" ) ) ,
182+ Arg :: Value ( value) | Arg :: Unexpected ( value) => LexError :: msg ( format_args ! (
183183 "missing required `{}`" ,
184184 value. to_string_lossy( )
185185 ) ) ,
0 commit comments