diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/abconfig.rs | 11 | ||||
-rw-r--r-- | src/abook.rs | 11 | ||||
-rw-r--r-- | src/bin/zot/main.rs | 1 | ||||
-rw-r--r-- | src/bin/zot/zot/abconfig.rs | 2 | ||||
-rw-r--r-- | src/lib.rs | 2 | ||||
-rw-r--r-- | src/verify.rs | 11 | ||||
-rw-r--r-- | src/zotapi.rs | 5 |
7 files changed, 18 insertions, 25 deletions
diff --git a/src/abconfig.rs b/src/abconfig.rs index ebb7e2b..8904ca3 100644 --- a/src/abconfig.rs +++ b/src/abconfig.rs @@ -14,13 +14,14 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see <https://www.gnu.org/licenses/>. -use crate::{client::Client, error::Error}; +use crate::{client::Client, error::Error, ZotAPI}; use serde::Deserialize; +use zotapi_derive::ZotAPI; /// A struct for storing a key value pair with a category in /// relation to a contact. Typically used to store permissions /// a given contact has on a given channel. -#[derive(Debug, Default, Deserialize)] +#[derive(Debug, Default, Deserialize, ZotAPI)] pub struct ABConfig { /// Database ID for this entry pub id: u32, @@ -41,12 +42,6 @@ pub struct ABConfig { pub v: String, } -impl ABConfig { - pub fn z() -> ABConfigRequest { - ABConfigRequest::default() - } -} - #[derive(Default)] pub struct ABConfigRequest { abook_id: Option<u32>, diff --git a/src/abook.rs b/src/abook.rs index d7d38cd..c7ceeb1 100644 --- a/src/abook.rs +++ b/src/abook.rs @@ -14,11 +14,12 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see <https://www.gnu.org/licenses/>. -use crate::{client::Client, error::Error, XChan}; +use crate::{client::Client, error::Error, XChan, ZotAPI}; use serde::Deserialize; use std::convert::TryFrom; +use zotapi_derive::ZotAPI; -#[derive(Debug, Default, Deserialize)] +#[derive(Debug, Default, Deserialize, ZotAPI)] pub struct Abook { #[serde(rename = "abook_id")] pub id: u32, @@ -105,12 +106,6 @@ pub struct Abook { } -impl Abook { - pub fn z() -> AbookRequest { - AbookRequest::default() - } -} - impl<'a> TryFrom<&'a str> for Abook { type Error = Error; diff --git a/src/bin/zot/main.rs b/src/bin/zot/main.rs index 70a7984..bf7b9b8 100644 --- a/src/bin/zot/main.rs +++ b/src/bin/zot/main.rs @@ -19,6 +19,7 @@ use clap::{clap_app, crate_authors, crate_version}; use dotenv::dotenv; use std::env; use std::str::FromStr; +use zotapi::ZotAPI; mod zot; diff --git a/src/bin/zot/zot/abconfig.rs b/src/bin/zot/zot/abconfig.rs index 14875c8..1d67a54 100644 --- a/src/bin/zot/zot/abconfig.rs +++ b/src/bin/zot/zot/abconfig.rs @@ -15,7 +15,7 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -use zotapi; +use zotapi::{self, ZotAPI}; pub async fn fetch(client: &zotapi::Client) { match zotapi::ABConfig::z().fetch(&client).await { @@ -24,6 +24,7 @@ mod item; mod network_stream; mod verify; mod xchan; +mod zotapi; pub use abconfig::ABConfig; pub use abook::Abook; @@ -35,6 +36,7 @@ pub use item::item; pub use network_stream::network_stream; pub use verify::Channel; pub use xchan::XChan; +pub use zotapi::ZotAPI; #[cfg(test)] mod tests { diff --git a/src/verify.rs b/src/verify.rs index 8edb2f1..57e250d 100644 --- a/src/verify.rs +++ b/src/verify.rs @@ -14,11 +14,12 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see <https://www.gnu.org/licenses/>. -use crate::{client::Client, error::Error, XChan}; +use crate::{client::Client, error::Error, XChan, ZotAPI}; use serde::Deserialize; use std::convert::TryFrom; +use zotapi_derive::ZotAPI; -#[derive(Deserialize, Debug)] +#[derive(Deserialize, Debug, ZotAPI)] pub struct Channel { #[serde(alias = "channel_id")] pub id: u32, @@ -129,12 +130,6 @@ pub struct Channel { pub xchan: XChan, } -impl Channel { - pub fn z() -> ChannelRequest { - ChannelRequest::default() - } -} - impl<'a> TryFrom<&'a str> for Channel { type Error = Error; diff --git a/src/zotapi.rs b/src/zotapi.rs new file mode 100644 index 0000000..42d8cde --- /dev/null +++ b/src/zotapi.rs @@ -0,0 +1,5 @@ +pub trait ZotAPI<T: Default> { + fn z() -> T { + T::default() + } +} |