Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add more specific error RequestIgnored #3481

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down
32 changes: 28 additions & 4 deletions src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))]
Expand All @@ -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::{
Expand Down Expand Up @@ -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<u32>,
) -> 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: () })
}
}
}
Expand All @@ -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 {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kchibisov asked in #3067 (comment):

What's the reason this error is here and not on the window for example?

Because it's specific to InnerSizeWriter, which is also in this module.

_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;
Expand Down