DioxusLabs/dioxus · error

The constructor function must be a zero-sized type (ZST). Co

Error message

The constructor function must be a zero-sized type (ZST). Consider using a function pointer or a closure without captured variables.

What it means

Lazy::new requires the constructor closure/function to be zero-sized so it can be stored in a const static. A closure capturing any variables has non-zero size_of::<F>() and cannot be embedded, so the const constructor panics with this guard message.

Source

Thrown at packages/fullstack/src/lazy.rs:43

    /// This internally calls `std::sync::OnceLock::new()` under the hood.
    #[allow(clippy::self_named_constructors)]
    pub const fn lazy() -> Self {
        Self {
            _phantom: std::marker::PhantomData,
            constructor: None,
            started_initialization: AtomicBool::new(false),
            value: std::sync::OnceLock::new(),
        }
    }

    pub const fn new<F, G, E>(constructor: F) -> Self
    where
        F: Fn() -> G + Copy,
        G: Future<Output = Result<T, E>> + Send + 'static,
        E: Into<CapturedError>,
    {
        if std::mem::size_of::<F>() != 0 {
            panic!(
                "The constructor function must be a zero-sized type (ZST). Consider using a function pointer or a closure without captured variables."
            );
        }

        // Prevent the constructor from being optimized out
        black_box(constructor);

        Self {
            _phantom: std::marker::PhantomData,
            value: std::sync::OnceLock::new(),
            started_initialization: AtomicBool::new(false),
            constructor: Some(blocking_initialize::<T, F, G, E>),
        }
    }

    /// Set the value of the `Lazy` instance.
    ///
    /// This should only be called once during the server setup phase, typically inside `dioxus::serve`.

View on GitHub (pinned to 24f6a829df)

Solutions

  1. The lazy constructor must be zero-sized. Use a function pointer or a closure that captures no variables.
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at packages/fullstack/src/lazy.rs:43 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of DioxusLabs/dioxus@24f6a829df (2026-08-23). Data as JSON: /api/errors/2ac607da9573b679. Report an issue: GitHub.