{"record":{"id":"c1b2fcb397b84832","repo":"emilk/egui","slug":"your-app-must-implement-as-any-mut-but-it-doesn","errorCode":null,"errorMessage":"Your app must implement `as_any_mut`, but it doesn't","messagePattern":"Your app must implement `as_any_mut`, but it doesn't","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/eframe/src/web/app_runner.rs","lineNumber":190,"sourceCode":"            .entry(egui::ViewportId::ROOT)\n            .or_default()\n            .native_pixels_per_point = Some(super::native_pixels_per_point());\n        runner.input.raw.system_theme = super::system_theme();\n\n        Ok(runner)\n    }\n\n    pub fn egui_ctx(&self) -> &egui::Context {\n        &self.egui_ctx\n    }\n\n    /// Get mutable access to the concrete [`App`] we enclose.\n    ///\n    /// This will panic if your app does not implement [`App::as_any_mut`].\n    pub fn app_mut<ConcreteApp: 'static + App>(&mut self) -> &mut ConcreteApp {\n        self.app\n            .as_any_mut()\n            .expect(\"Your app must implement `as_any_mut`, but it doesn't\")\n            .downcast_mut::<ConcreteApp>()\n            .expect(\"app_mut got the wrong type of App\")\n    }\n\n    pub fn auto_save_if_needed(&mut self) {\n        let time_since_last_save = now_sec() - self.last_save_time;\n        if time_since_last_save > self.app.auto_save_interval().as_secs_f64() {\n            self.save();\n        }\n    }\n\n    pub fn save(&mut self) {\n        if self.app.persist_egui_memory() {\n            super::storage::save_memory(&self.egui_ctx);\n        }\n        if let Some(storage) = self.frame.storage_mut() {\n            self.app.save(storage);\n        }","sourceCodeStart":172,"sourceCodeEnd":208,"githubUrl":"https://github.com/emilk/egui/blob/441971a776322a482e371775219380eca812cfa9/crates/eframe/src/web/app_runner.rs#L172-L208","documentation":"`AppRunner::app_mut<ConcreteApp>` requires the enclosed `App` to expose `&mut dyn Any` via `App::as_any_mut`; the `expect` panics when `as_any_mut()` returns `None`. This happens when a custom `App` implementation does not implement `as_any_mut` (e.g. returns `None` from a default/no-op impl), making the downcast to the concrete type impossible. eframe uses this for inspection/inspection plugins and for callers wanting typed access to their app.","triggerScenarios":"Calling `runner.app_mut::<MyApp>()` (directly or via eframe features like inspection) when `MyApp`'s `as_any_mut` returns `None` because it was not implemented or was implemented to return `None`.","commonSituations":"Implementing `App` with an empty/`unimplemented!`-style `as_any_mut` stub; copying an old example where the trait method was optional; mixing trait objects so the downcast target type doesn't match the real concrete type.","solutions":["Implement `as_any_mut` correctly: `fn as_any_mut(&mut self) -> Option<&mut dyn Any> { Some(self) }`.","Verify the generic parameter matches the actual concrete app type (the second `expect` in the same function guards against type mismatch).","Remove any manual `None` return or `panic!` stub left in `as_any_mut`.","If you only need read access, use `app()`/`as_any` analogues — but still implement the method properly."],"exampleFix":"// before\nimpl App for MyApp {\n    fn as_any_mut(&mut self) -> Option<&mut dyn Any> { None }\n}\n// after\nuse std::any::Any;\nimpl App for MyApp {\n    fn as_any_mut(&mut self) -> Option<&mut dyn Any> { Some(self) }\n}","handlingStrategy":"type-guard","validationCode":"// Verify typed access works before calling app_mut\nfn can_downcast_to<A: App + 'static>(runner: &AppRunner) -> bool {\n    runner.app.as_any().map_or(false, |a| a.is::<A>())\n}","typeGuard":"fn as_my_app<'a>(app: &'a mut dyn App) -> Option<&'a mut MyApp> {\n    app.as_any_mut()?.downcast_mut::<MyApp>()\n}","tryCatchPattern":"// eframe panics rather than returning Result, so guard first:\nif let Some(my_app) = runner.app.as_any_mut().and_then(|a| a.downcast_mut::<MyApp>()) {\n    my_app.do_mutate();\n}","preventionTips":["Always implement as_any_mut as Some(self) in App impls","Never stub as_any_mut with None or panic!","Match the generic type parameter to the actual concrete app type"],"tags":["panic","eframe","downcast","app-trait","wasm"],"backgroundTag":"method-not-implemented","analyzedSha":"441971a776322a482e371775219380eca812cfa9","analyzedAt":"2026-09-12T04:29:21.500Z","contentChangedAt":"2026-09-12T04:29:21.500Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}