From 8fd5bde369357a57d724d34bd391eea338a944ab Mon Sep 17 00:00:00 2001 From: Daniel McNab <36049421+DJMcNab@users.noreply.github.com> Date: Tue, 14 Jan 2025 09:39:17 +0000 Subject: [PATCH] Make `DriverCtx` publicly constructable again (#821) Follow-up to #808 Also adds a test to limit the risk of future regression. --- masonry/src/app_driver.rs | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/masonry/src/app_driver.rs b/masonry/src/app_driver.rs index f44747510..09fecd4b7 100644 --- a/masonry/src/app_driver.rs +++ b/masonry/src/app_driver.rs @@ -8,7 +8,13 @@ use crate::{Action, RenderRoot, WidgetId}; /// /// Currently holds a reference to the [`RenderRoot`]. pub struct DriverCtx<'a> { - pub(crate) render_root: &'a mut RenderRoot, + // We make no guarantees about the fields of this struct, but + // they must all be public so that the type can be constructed + // externally. + // This is needed for external users, whilst our external API + // is not yet designed. + #[doc(hidden)] + pub render_root: &'a mut RenderRoot, } /// A trait for defining how your app interacts with the Masonry widget tree. @@ -40,3 +46,15 @@ impl DriverCtx<'_> { self.render_root.needs_rewrite_passes() } } + +#[cfg(doctest)] +/// Doctests aren't collected under `cfg(test)`; we can use `cfg(doctest)` instead +mod doctests { + /// ```no_run + /// use masonry::DriverCtx; + /// let _ctx = DriverCtx { + /// render_root: unimplemented!() + /// }; + /// ``` + const _DRIVER_CTX_EXTERNALLY_CONSTRUCTIBLE: () = {}; +}