Compare commits
2 commits
Author | SHA1 | Date | |
---|---|---|---|
2e7b980a34 | |||
f2ca095fb6 |
3 changed files with 65 additions and 27 deletions
12
Cargo.toml
12
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" }
|
||||
|
|
|
@ -715,9 +715,7 @@ mod tests {
|
|||
let elem3: Element = "<presence scansion:strict='false' xmlns='foo'><foo/>\n</presence>"
|
||||
.parse()
|
||||
.unwrap();
|
||||
let elem4: Element = "<presence xmlns='foo'><foo/>\t</presence>"
|
||||
.parse()
|
||||
.unwrap();
|
||||
let elem4: Element = "<presence xmlns='foo'><foo/>\t</presence>".parse().unwrap();
|
||||
let scan2 = ScanElement::new(elem3);
|
||||
|
||||
assert_eq!(scan2, elem4);
|
||||
|
@ -725,9 +723,7 @@ mod tests {
|
|||
let elem5: Element = "<presence scansion:strict='false' xmlns='foo'> <foo/>\n</presence>"
|
||||
.parse()
|
||||
.unwrap();
|
||||
let elem6: Element = "<presence xmlns='foo'><foo/>\t</presence>"
|
||||
.parse()
|
||||
.unwrap();
|
||||
let elem6: Element = "<presence xmlns='foo'><foo/>\t</presence>".parse().unwrap();
|
||||
let scan3 = ScanElement::new(elem5);
|
||||
|
||||
assert_eq!(scan3, elem6);
|
||||
|
@ -748,9 +744,7 @@ mod tests {
|
|||
let elem3: Element = "<presence scansion:strict='true' xmlns='foo'><foo/>\n</presence>"
|
||||
.parse()
|
||||
.unwrap();
|
||||
let elem4: Element = "<presence xmlns='foo'><foo/>\t</presence>"
|
||||
.parse()
|
||||
.unwrap();
|
||||
let elem4: Element = "<presence xmlns='foo'><foo/>\t</presence>".parse().unwrap();
|
||||
let scan2 = ScanElement::new(elem3);
|
||||
|
||||
assert_eq!(scan2, elem4);
|
||||
|
@ -758,9 +752,7 @@ mod tests {
|
|||
let elem5: Element = "<presence scansion:strict='true' xmlns='foo'> <foo/>\n</presence>"
|
||||
.parse()
|
||||
.unwrap();
|
||||
let elem6: Element = "<presence xmlns='foo'><foo/>\t</presence>"
|
||||
.parse()
|
||||
.unwrap();
|
||||
let elem6: Element = "<presence xmlns='foo'><foo/>\t</presence>".parse().unwrap();
|
||||
let scan3 = ScanElement::new(elem5);
|
||||
|
||||
assert_eq!(scan3, elem6);
|
||||
|
@ -771,9 +763,7 @@ mod tests {
|
|||
let elem1: Element = "<presence scansion:strict='false' xmlns='foo'>abc</presence>"
|
||||
.parse()
|
||||
.unwrap();
|
||||
let elem2: Element = "<presence xmlns='foo'> abc </presence>"
|
||||
.parse()
|
||||
.unwrap();
|
||||
let elem2: Element = "<presence xmlns='foo'> abc </presence>".parse().unwrap();
|
||||
let scan1 = ScanElement::new(elem1);
|
||||
|
||||
assert_ne!(scan1, elem2);
|
||||
|
@ -781,9 +771,7 @@ mod tests {
|
|||
let elem3: Element = "<presence scansion:strict='false' xmlns='foo'> </presence>"
|
||||
.parse()
|
||||
.unwrap();
|
||||
let elem4: Element = "<presence xmlns='foo'></presence>"
|
||||
.parse()
|
||||
.unwrap();
|
||||
let elem4: Element = "<presence xmlns='foo'></presence>".parse().unwrap();
|
||||
let scan2 = ScanElement::new(elem3);
|
||||
|
||||
assert_ne!(scan2, elem4);
|
||||
|
@ -794,9 +782,7 @@ mod tests {
|
|||
let elem1: Element = "<presence scansion:strict='true' xmlns='foo'>abc</presence>"
|
||||
.parse()
|
||||
.unwrap();
|
||||
let elem2: Element = "<presence xmlns='foo'> abc </presence>"
|
||||
.parse()
|
||||
.unwrap();
|
||||
let elem2: Element = "<presence xmlns='foo'> abc </presence>".parse().unwrap();
|
||||
let scan1 = ScanElement::new(elem1);
|
||||
|
||||
assert_ne!(scan1, elem2);
|
||||
|
@ -804,9 +790,7 @@ mod tests {
|
|||
let elem3: Element = "<presence scansion:strict='true' xmlns='foo'> </presence>"
|
||||
.parse()
|
||||
.unwrap();
|
||||
let elem4: Element = "<presence xmlns='foo'></presence>"
|
||||
.parse()
|
||||
.unwrap();
|
||||
let elem4: Element = "<presence xmlns='foo'></presence>".parse().unwrap();
|
||||
let scan2 = ScanElement::new(elem3);
|
||||
|
||||
assert_ne!(scan2, elem4);
|
||||
|
|
48
src/types.rs
48
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<Name, Entity>;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
|
|
Loading…
Reference in a new issue