eval
use cjs::eval;
const X: f64 = eval! {
const x = 5;
String(x * Math.PI)
};
Custom Derive
use cjs::Reflect;
#[derive(Debug, Reflect)]
#[reflect("reflect_s")]
struct S {
foo: String,
bar: String
}
reflect_s!{
let out = ["impl ToString for S {"];
out.push("fn to_string(&self) -> String {");
out.push("vec![");
out.push(ctx.fields.map(field => "(&" + field.name + ").to_string()").join(", "));
out.push("].join(" + '"' + " & " + '"' + ")");
out.push("}");
out.push("}");
out.join("\n");
}
Prior Work