1919#[ cfg( doctest) ]
2020pub struct ReadmeDoctests ;
2121
22- /// `Result` that defaults to [`Error`]
23- pub type Result < T , E = Error > = std:: result:: Result < T , E > ;
24-
25- /// Argument error type for use with lexarg
26- pub struct Error {
27- msg : String ,
28- }
29-
30- impl Error {
31- /// Create a new error object from a printable error message.
32- #[ cold]
33- pub fn msg < M > ( message : M ) -> Self
34- where
35- M : std:: fmt:: Display ,
36- {
37- Self {
38- msg : message. to_string ( ) ,
39- }
40- }
41- }
42-
43- impl From < ErrorContext < ' _ > > for Error {
44- #[ cold]
45- fn from ( error : ErrorContext < ' _ > ) -> Self {
46- Self :: msg ( error. to_string ( ) )
47- }
48- }
49-
50- impl std:: fmt:: Debug for Error {
51- fn fmt ( & self , formatter : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
52- self . msg . fmt ( formatter)
53- }
54- }
55-
56- impl std:: fmt:: Display for Error {
57- fn fmt ( & self , formatter : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
58- self . msg . fmt ( formatter)
59- }
60- }
61-
62- /// Collect context for creating an [`Error`]
22+ /// Collect context for creating an error
6323#[ derive( Debug ) ]
6424pub struct ErrorContext < ' a > {
6525 msg : String ,
66- within : Option < lexarg :: Arg < ' a > > ,
67- unexpected : Option < lexarg :: Arg < ' a > > ,
26+ within : Option < lexarg_parser :: Arg < ' a > > ,
27+ unexpected : Option < lexarg_parser :: Arg < ' a > > ,
6828}
6929
7030impl < ' a > ErrorContext < ' a > {
@@ -81,16 +41,16 @@ impl<'a> ErrorContext<'a> {
8141 }
8242 }
8343
84- /// [`Arg`][lexarg ::Arg] the error occurred within
44+ /// [`Arg`][lexarg_parser ::Arg] the error occurred within
8545 #[ cold]
86- pub fn within ( mut self , within : lexarg :: Arg < ' a > ) -> Self {
46+ pub fn within ( mut self , within : lexarg_parser :: Arg < ' a > ) -> Self {
8747 self . within = Some ( within) ;
8848 self
8949 }
9050
91- /// The failing [`Arg`][lexarg ::Arg]
51+ /// The failing [`Arg`][lexarg_parser ::Arg]
9252 #[ cold]
93- pub fn unexpected ( mut self , unexpected : lexarg :: Arg < ' a > ) -> Self {
53+ pub fn unexpected ( mut self , unexpected : lexarg_parser :: Arg < ' a > ) -> Self {
9454 self . unexpected = Some ( unexpected) ;
9555 self
9656 }
@@ -112,10 +72,10 @@ impl std::fmt::Display for ErrorContext<'_> {
11272 if let Some ( unexpected) = & self . unexpected {
11373 write ! ( formatter, ", found `" ) ?;
11474 match unexpected {
115- lexarg :: Arg :: Short ( short) => write ! ( formatter, "-{short}" ) ?,
116- lexarg :: Arg :: Long ( long) => write ! ( formatter, "--{long}" ) ?,
117- lexarg :: Arg :: Escape ( value) => write ! ( formatter, "{value}" ) ?,
118- lexarg :: Arg :: Value ( value) | lexarg :: Arg :: Unexpected ( value) => {
75+ lexarg_parser :: Arg :: Short ( short) => write ! ( formatter, "-{short}" ) ?,
76+ lexarg_parser :: Arg :: Long ( long) => write ! ( formatter, "--{long}" ) ?,
77+ lexarg_parser :: Arg :: Escape ( value) => write ! ( formatter, "{value}" ) ?,
78+ lexarg_parser :: Arg :: Value ( value) | lexarg_parser :: Arg :: Unexpected ( value) => {
11979 write ! ( formatter, "{}" , value. to_string_lossy( ) ) ?;
12080 }
12181 }
@@ -124,10 +84,10 @@ impl std::fmt::Display for ErrorContext<'_> {
12484 if let Some ( within) = & self . within {
12585 write ! ( formatter, " when parsing `" ) ?;
12686 match within {
127- lexarg :: Arg :: Short ( short) => write ! ( formatter, "-{short}" ) ?,
128- lexarg :: Arg :: Long ( long) => write ! ( formatter, "--{long}" ) ?,
129- lexarg :: Arg :: Escape ( value) => write ! ( formatter, "{value}" ) ?,
130- lexarg :: Arg :: Value ( value) | lexarg :: Arg :: Unexpected ( value) => {
87+ lexarg_parser :: Arg :: Short ( short) => write ! ( formatter, "-{short}" ) ?,
88+ lexarg_parser :: Arg :: Long ( long) => write ! ( formatter, "--{long}" ) ?,
89+ lexarg_parser :: Arg :: Escape ( value) => write ! ( formatter, "{value}" ) ?,
90+ lexarg_parser :: Arg :: Value ( value) | lexarg_parser :: Arg :: Unexpected ( value) => {
13191 write ! ( formatter, "{}" , value. to_string_lossy( ) ) ?;
13292 }
13393 }
0 commit comments