casualx / format_xml Goto Github PK
View Code? Open in Web Editor NEWMinimal compiletime templating for XML in Rust!
License: MIT License
Minimal compiletime templating for XML in Rust!
License: MIT License
I'd like to compose XMLs with functions. That works but solution is a bit noisy:
use format_xml::xml;
fn f(x: u8, y: u8) -> String {
let result = xml! {
<A>{x}</A>
<B>{y}</B>
}
.to_string();
result
}
fn main() {
let x = xml! {
<C>
{f(1, 2)}
</C>
<C>
{f(2, 1)}
</C>
}
.to_string();
println!("{}", x);
}
Removing intermediate result
variable
fn f(x: u8, y: u8) -> String {
xml! {
<A>{x}</A>
<B>{y}</B>
}
.to_string()
}
causes unobvious compiler error:
error: expected expression, found `.`
--> src/main.rs:8:5
|
8 | .to_string()
| ^ expected expression
error[E0308]: mismatched types
--> src/main.rs:4:5
|
4 | / xml! {
5 | | <A>{x}</A>
6 | | <B>{y}</B>
7 | | }
| | ^
| | |
| |_____expected `()`, found struct `std::fmt::Arguments`
| help: consider using a semicolon here
|
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
Which can be fixed by wrapping xml!
macros usage with ()
or {}
:
fn f(x: u8, y: u8) -> String {
(xml! {
<A>{x}</A>
<B>{y}</B>
})
.to_string()
}
Returning std::fmt::Arguments
without constructing intermediate String
would be even better, but I didn't find a way to satisfy borrow checker.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.