diff --git a/Cargo.toml b/Cargo.toml index 4f85311..e633725 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,7 +13,13 @@ minidom = "*" xmpp-parsers = "0.20" nom_locate = "4.0.0" rand = "0.8" +quote = { version = "1.0", optional = true } +proc-macro2 = { version = "1.0", optional = true } -# [patch.crates-io] -# jid = { path = "../xmpp-rs/jid" } -# minidom = { path = "../xmpp-rs/minidom" } +[features] +quote = ["dep:quote", "dep:proc-macro2", "jid/quote"] + +[patch.crates-io] +jid = { git = "https://gitlab.com/xmpp-rs/xmpp-rs" } +minidom = { git = "https://gitlab.com/xmpp-rs/xmpp-rs" } +xmpp-parsers = { git = "https://gitlab.com/xmpp-rs/xmpp-rs" } diff --git a/src/types.rs b/src/types.rs index 26f39ac..22310d8 100644 --- a/src/types.rs +++ b/src/types.rs @@ -7,6 +7,10 @@ use std::collections::HashMap; use jid::Jid; +#[cfg(feature = "quote")] +use proc_macro2::TokenStream; +#[cfg(feature = "quote")] +use quote::{quote, ToTokens}; #[derive(Debug, PartialEq)] pub enum VariableAttr { @@ -67,11 +71,55 @@ impl Client { } } +#[cfg(feature = "quote")] +impl ToTokens for Client { + fn to_tokens(&self, tokens: &mut TokenStream) { + let jid = &self.jid; + let password = &self.password; + let custom_host = { + let tmp = &self.custom_host; + if self.custom_host.is_none() { + quote! { None } + } else { + quote! { #tmp } + } + }; + let custom_port = { + let tmp = &self.custom_port; + if self.custom_port.is_none() { + quote! { None } + } else { + quote! { #tmp } + } + }; + + let t = quote! { + Client { + jid: #jid, + password: String::from(#password), + custom_host: #custom_host, + custom_port: #custom_port, + } + }; + + tokens.extend(t); + } +} + #[derive(Debug, Clone, PartialEq)] pub enum Entity { Client(Client), } +#[cfg(feature = "quote")] +impl ToTokens for Entity { + fn to_tokens(&self, tokens: &mut TokenStream) { + tokens.extend(match self { + Entity::Client(client) => quote! { Entity::Client(#client) }, + }); + } +} + pub type Context = HashMap; #[derive(Debug, Clone, PartialEq)]