LeRoyce Pearson Blog

Defining a a recursive type

Or any type that requres you to define it in rust and gluon.


extern crate gluon_codegen;

#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, VmType, Getable, Pushable)]
#[gluon(vm_type = "dom_types.Node")]
pub enum Node {
    Element {
        children: Vec<Node>,

use gluon::{vm::api::FunctionRef, Compiler};

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let vm = gluon::new_vm();

    let node_source = include_str!("node.glu");
        .load_script(&vm, "dom_types", &node_source)
        .unwrap_or_else(|e| panic!("{}", e));



let { Tag } = import! dom_types.tag

let Node =
	| Element { tag: Tag, children: Array Node }
	| Text String
	| Empty

{ Node }

Struct-like enum variants cause Getable to panic

Need to find a minimum code reproduction of the issue.

Update: Nevermind. It's working now. I have a recursive type, so the marshalling code can't be generated, but deriving Getable and Pushable seems to work well.

Generating Option fields doesn't work

What the fuck? Did he change some language semantics without updating the derive macro? If he imported the type and then used it instead of using the fully qualified name, it work.