{"record":{"id":"2ac607da9573b679","repo":"DioxusLabs/dioxus","slug":"the-constructor-function-must-be-a-zero-sized-type","errorCode":null,"errorMessage":"The constructor function must be a zero-sized type (ZST). Consider using a function pointer or a closure without captured variables.","messagePattern":"The constructor function must be a zero-sized type \\(ZST\\)\\. Consider using a function pointer or a closure without captured variables\\.","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/fullstack/src/lazy.rs","lineNumber":43,"sourceCode":"    /// This internally calls `std::sync::OnceLock::new()` under the hood.\n    #[allow(clippy::self_named_constructors)]\n    pub const fn lazy() -> Self {\n        Self {\n            _phantom: std::marker::PhantomData,\n            constructor: None,\n            started_initialization: AtomicBool::new(false),\n            value: std::sync::OnceLock::new(),\n        }\n    }\n\n    pub const fn new<F, G, E>(constructor: F) -> Self\n    where\n        F: Fn() -> G + Copy,\n        G: Future<Output = Result<T, E>> + Send + 'static,\n        E: Into<CapturedError>,\n    {\n        if std::mem::size_of::<F>() != 0 {\n            panic!(\n                \"The constructor function must be a zero-sized type (ZST). Consider using a function pointer or a closure without captured variables.\"\n            );\n        }\n\n        // Prevent the constructor from being optimized out\n        black_box(constructor);\n\n        Self {\n            _phantom: std::marker::PhantomData,\n            value: std::sync::OnceLock::new(),\n            started_initialization: AtomicBool::new(false),\n            constructor: Some(blocking_initialize::<T, F, G, E>),\n        }\n    }\n\n    /// Set the value of the `Lazy` instance.\n    ///\n    /// This should only be called once during the server setup phase, typically inside `dioxus::serve`.","sourceCodeStart":25,"sourceCodeEnd":61,"githubUrl":"https://github.com/DioxusLabs/dioxus/blob/24f6a829df0dfa203961a98ea4cae21c2ff27e28/packages/fullstack/src/lazy.rs#L25-L61","documentation":"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.","triggerScenarios":"Thrown at packages/fullstack/src/lazy.rs:43 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["The lazy constructor must be zero-sized. Use a function pointer or a closure that captures no variables."],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"24f6a829df0dfa203961a98ea4cae21c2ff27e28","analyzedAt":"2026-08-23T07:10:14.078Z","contentChangedAt":"2026-08-23T07:10:14.078Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}