refactor: add strictly typed tags

* Add custom error variant

This can be useful to propagate errors not conforming to available
variants. Also to convert other errors in `crate::Error` without having
explicit conversion defined, with `error.to_string()`

* Implement `Tag` and define protocol serialization

A Tag structure have been implemented with dedicated field types. Then
custom serde serialization is derived to map the structure to current
protocol json array as per NIP01.

This adds compile and run time type checking to always ensure wrong
string data are never stored or processed. With strict typed fields and
custom serde derivation this checks can be done at time of serialization,
saving work for internal handling of the actual data.

tests for possible data violations are added, and gives good example of
kind of errors it will through for different cases.

* Use String for URL
This commit is contained in:
Raj
2022-01-19 07:42:58 -06:00
committed by GitHub
parent c605d75bb4
commit 179928378e
3 changed files with 318 additions and 0 deletions
+2
View File
@@ -40,6 +40,8 @@ pub enum Error {
ConfigError(config::ConfigError),
#[error("Data directory does not exist")]
DatabaseDirError,
#[error("Custom Error : {0}")]
CustomError(String),
}
impl From<rusqlite::Error> for Error {