Compare commits

...

1 commit
main ... quote

Author SHA1 Message Date
e1d512e82f
Add quote support for Entity
Signed-off-by: Maxime “pep” Buquet <pep@bouah.net>
2023-10-29 13:48:15 +01:00
2 changed files with 31 additions and 1 deletions

View file

@ -8,11 +8,13 @@ description = "Reimplementation of the Scansion project in Rust"
[dependencies]
nom = "7.1"
jid = { version = "*", features = [ "minidom" ] }
jid = { version = "*", features = [ "minidom", "quote" ] }
minidom = "*"
xmpp-parsers = "0.20"
nom_locate = "4.0.0"
rand = "0.8"
proc-macro2 = "*"
quote = "1.0"
# [patch.crates-io]
# jid = { path = "../xmpp-rs/jid" }

View file

@ -7,6 +7,8 @@
use std::collections::HashMap;
use jid::Jid;
use proc_macro2::TokenStream;
use quote::{quote, ToTokens};
#[derive(Debug, PartialEq)]
pub enum VariableAttr {
@ -67,11 +69,37 @@ impl Client {
}
}
impl ToTokens for Client {
fn to_tokens(&self, tokens: &mut TokenStream) {
let custom_host = if self.custom_host.is_none() { quote! { None } } else { quote! { #self.custom_host } };
let custom_port = if self.custom_port.is_none() { quote! { None } } else { quote! { #self.custom_port } };
let t = quote! {
Client {
jid: #self.jid,
password: String::from(#self.password),
custom_host: #custom_host,
custom_port: #custom_port,
}
};
tokens.extend(t);
}
}
#[derive(Debug, Clone, PartialEq)]
pub enum Entity {
Client(Client),
}
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<Name, Entity>;
#[derive(Debug, Clone, PartialEq)]