33
44//! Tag
55
6- use std :: fmt;
7- use std :: num:: ParseIntError ;
8- use std :: str:: FromStr ;
6+ use core :: fmt;
7+ use core :: num:: ParseIntError ;
8+ use core :: str:: FromStr ;
99
1010use secp256k1:: schnorr:: Signature ;
1111use secp256k1:: XOnlyPublicKey ;
@@ -14,48 +14,99 @@ use serde::ser::SerializeSeq;
1414use serde:: { Deserialize , Deserializer , Serialize , Serializer } ;
1515
1616use super :: id:: { self , EventId } ;
17- use crate :: nips:: nip26:: Conditions ;
17+ use crate :: nips:: nip26:: { Conditions , Error as Nip26Error } ;
1818use crate :: { Kind , Timestamp , UncheckedUrl } ;
1919
2020/// [`Tag`] error
21- #[ derive( Debug , thiserror :: Error ) ]
21+ #[ derive( Debug ) ]
2222pub enum Error {
2323 /// Impossible to parse [`Marker`]
24- #[ error( "impossible to parse marker" ) ]
2524 MarkerParseError ,
2625 /// Unknown [`Report`]
27- #[ error( "unknown report type" ) ]
2826 UnknownReportType ,
2927 /// Impossible to find tag kind
30- #[ error( "impossible to find tag kind" ) ]
3128 KindNotFound ,
3229 /// Invalid length
33- #[ error( "invalid length" ) ]
3430 InvalidLength ,
31+ /// Invalid Zap Request
32+ InvalidZapRequest ,
3533 /// Impossible to parse integer
36- #[ error( transparent) ]
37- ParseIntError ( #[ from] ParseIntError ) ,
34+ ParseIntError ( ParseIntError ) ,
3835 /// Secp256k1
39- #[ error( transparent) ]
40- Secp256k1 ( #[ from] secp256k1:: Error ) ,
36+ Secp256k1 ( secp256k1:: Error ) ,
4137 /// Hex decoding error
42- #[ error( transparent) ]
43- Hex ( #[ from] bitcoin_hashes:: hex:: Error ) ,
38+ Hex ( bitcoin_hashes:: hex:: Error ) ,
4439 /// Url parse error
45- #[ error( "invalid url: {0}" ) ]
46- Url ( #[ from] url:: ParseError ) ,
40+ Url ( url:: ParseError ) ,
4741 /// EventId error
48- #[ error( transparent) ]
49- EventId ( #[ from] id:: Error ) ,
42+ EventId ( id:: Error ) ,
5043 /// NIP26 error
51- #[ error( transparent) ]
52- Nip26 ( #[ from] crate :: nips:: nip26:: Error ) ,
44+ NIP26 ( Nip26Error ) ,
5345 /// Event Error
54- #[ error( transparent) ]
55- Event ( #[ from] crate :: event:: Error ) ,
56- /// Invalid Zap Request
57- #[ error( "Invalid Zap request" ) ]
58- InvalidZapRequest ,
46+ Event ( crate :: event:: Error ) ,
47+ }
48+
49+ impl std:: error:: Error for Error { }
50+
51+ impl fmt:: Display for Error {
52+ fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
53+ match self {
54+ Self :: MarkerParseError => write ! ( f, "impossible to parse marker" ) ,
55+ Self :: UnknownReportType => write ! ( f, "unknown report type" ) ,
56+ Self :: KindNotFound => write ! ( f, "impossible to find tag kind" ) ,
57+ Self :: InvalidLength => write ! ( f, "invalid length" ) ,
58+ Self :: InvalidZapRequest => write ! ( f, "invalid Zap request" ) ,
59+ Self :: ParseIntError ( e) => write ! ( f, "{e}" ) ,
60+ Self :: Secp256k1 ( e) => write ! ( f, "{e}" ) ,
61+ Self :: Hex ( e) => write ! ( f, "{e}" ) ,
62+ Self :: Url ( e) => write ! ( f, "{e}" ) ,
63+ Self :: EventId ( e) => write ! ( f, "{e}" ) ,
64+ Self :: NIP26 ( e) => write ! ( f, "{e}" ) ,
65+ Self :: Event ( e) => write ! ( f, "{e}" ) ,
66+ }
67+ }
68+ }
69+
70+ impl From < ParseIntError > for Error {
71+ fn from ( e : ParseIntError ) -> Self {
72+ Self :: ParseIntError ( e)
73+ }
74+ }
75+
76+ impl From < secp256k1:: Error > for Error {
77+ fn from ( e : secp256k1:: Error ) -> Self {
78+ Self :: Secp256k1 ( e)
79+ }
80+ }
81+
82+ impl From < bitcoin_hashes:: hex:: Error > for Error {
83+ fn from ( e : bitcoin_hashes:: hex:: Error ) -> Self {
84+ Self :: Hex ( e)
85+ }
86+ }
87+
88+ impl From < url:: ParseError > for Error {
89+ fn from ( e : url:: ParseError ) -> Self {
90+ Self :: Url ( e)
91+ }
92+ }
93+
94+ impl From < id:: Error > for Error {
95+ fn from ( e : id:: Error ) -> Self {
96+ Self :: EventId ( e)
97+ }
98+ }
99+
100+ impl From < Nip26Error > for Error {
101+ fn from ( e : Nip26Error ) -> Self {
102+ Self :: NIP26 ( e)
103+ }
104+ }
105+
106+ impl From < crate :: event:: Error > for Error {
107+ fn from ( e : crate :: event:: Error ) -> Self {
108+ Self :: Event ( e)
109+ }
59110}
60111
61112/// Marker
0 commit comments