diff --git a/CHANGELOG.md b/CHANGELOG.md index 1387d34a5d..843b02d75d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ Unreleased` header. # Unreleased +- **Breaking:** Use `RequestIgnored` as the error type in `InnerSizeWriter::request_inner_size`. - Fix compatibility with 32-bit platforms without 64-bit atomics. - On X11, fix swapped instance and general class names. - **Breaking:** Removed unnecessary generic parameter `T` from `EventLoopWindowTarget`. diff --git a/src/event.rs b/src/event.rs index 798721c0fc..b31369704e 100644 --- a/src/event.rs +++ b/src/event.rs @@ -32,6 +32,8 @@ //! //! [`EventLoop::run(...)`]: crate::event_loop::EventLoop::run //! [`ControlFlow::WaitUntil`]: crate::event_loop::ControlFlow::WaitUntil +use std::error::Error; +use std::fmt; use std::path::PathBuf; use std::sync::{Mutex, Weak}; #[cfg(not(web_platform))] @@ -43,7 +45,6 @@ use smol_str::SmolStr; #[cfg(web_platform)] use web_time::Instant; -use crate::error::ExternalError; #[cfg(doc)] use crate::window::Window; use crate::{ @@ -1126,16 +1127,23 @@ impl InnerSizeWriter { Self { new_inner_size } } - /// Try to request inner size which will be set synchroniously on the window. + /// Try to request a new inner size which will be set synchronously on the + /// window. + /// + /// + /// # Errors + /// + /// This method returns an error when the request was ignored because it + /// was done asynchronously, outside the event loop callback. pub fn request_inner_size( &mut self, new_inner_size: PhysicalSize, - ) -> Result<(), ExternalError> { + ) -> Result<(), RequestIgnored> { if let Some(inner) = self.new_inner_size.upgrade() { *inner.lock().unwrap() = new_inner_size; Ok(()) } else { - Err(ExternalError::Ignored) + Err(RequestIgnored { _priv: () }) } } } @@ -1146,6 +1154,22 @@ impl PartialEq for InnerSizeWriter { } } +/// The request to change the inner size synchronously was ignored. +/// +/// See [`InnerSizeWriter::request_inner_size`] for details. +#[derive(Debug, Clone)] // Explicitly not other traits, in case we want to extend it in the future +pub struct RequestIgnored { + _priv: (), +} + +impl fmt::Display for RequestIgnored { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> { + f.write_str("the request to change the inner size was ignored") + } +} + +impl Error for RequestIgnored {} + #[cfg(test)] mod tests { use crate::event;