slint-ui/slint · error

Components written in Rust can not get embedded yet.

Error message

Components written in Rust can not get embedded yet.

What it means

The Rust code generator emits a todo!() when it must generate code for a component that is embedded into a parent item tree, because embedding components written in Rust is not yet supported by the generator. The resulting binary panics at runtime with 'Components written in Rust can not get embedded yet.' if that code path executes.

Solutions

  1. Restructure the .slint so the Rust-generated component is only used as a top-level component, not embedded
  2. Flatten the nesting: inline the child component's contents into the parent
  3. Use the interpreter API for components that need embedding, or file an issue/upstream feature request

Example fix

// before (App.slint embeds Child generated for Rust)
component Child { ... } component App { Child {} }
// after: make Child a top-level component and instantiate it from Rust as its own component instance
Defensive patterns

Strategy: validation

Validate before calling

// design-time check: keep Rust-backend components top-level
dfn/audit .slint files so no component intended for Rust codegen is nested inside another element tree

Try / catch

// todo!() aborts; the guard is structural: never generate embedded Rust components
// flatten nested components in the .slint before codegen

Prevention

When it happens

Trigger: Compiling a .slint component that is instantiated inside another element's tree (parent_ctx.is_some()) rather than as a top-level component, when generating Rust code — i.e. an embedded/nested component in the Rust backend.

Common situations: Using advanced slint! setups where sub-components get embedded; popups or nested component instantiation patterns hitting the embedding path; migrating a design from the interpreter (which supports embedding) to generated Rust.

Understand the failure class

Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.

Related errors


AI-assisted analysis of slint-ui/slint@3a7e700487 (2026-09-16). Data as JSON: /api/errors/7f56381019adb535. Report an issue: GitHub.

Appendix: source

Thrown at internal/compiler/generator/rust.rs:2358

        quote!(SharedGlobals::new(sp::VRc::downgrade(&self_dyn_rc)))
    };
    // The root component owns the freshly created `SharedGlobals` and is responsible for running
    // its eager initialization. The root's own `globals` field must be set *before* that init
    // runs, because a global binding (e.g. `Palette.color-scheme`) may resolve the root's window
    // adapter through `globals` during evaluation. Popups and sub-components receive an already
    // initialized `SharedGlobals`, so they skip this step.
    let set_and_init_globals = if is_root_component {
        quote!(
            let _ = sp::VRc::map(self_rc.clone(), |x| x).as_pin_ref().globals.set(globals.clone());
            globals.init_globals();
        )
    } else {
        quote!()
    };
    let globals_arg = is_popup.then(|| quote!(globals: sp::Rc<SharedGlobals>));

    let embedding_function = if parent_ctx.is_some() {
        quote!(todo!("Components written in Rust can not get embedded yet."))
    } else {
        quote!(false)
    };

    let parent_item_expression = parent_ctx.map(|parent| parent.repeater_index.map_or_else(|| {
        // No repeater index, this could be a PopupWindow
        quote!{
            if let Some(parent_rc) = self.parent.clone().upgrade() {
                let parent_origin = sp::VRcMapped::origin(&parent_rc);
                // TODO: store popup index in ctx and set it here instead of 0?
                *_result = sp::ItemRc::new_root(parent_origin).downgrade();
            }
        }
    }, |idx| {
        let current_sub_component = &root.sub_components[parent.sub_component];
        let sub_component_offset = current_sub_component.repeated[idx].index_in_tree;

        quote!{

View on GitHub (pinned to 3a7e700487)