mirror of
https://github.com/rust-windowing/winit.git
synced 2026-09-01 06:10:07 -04:00
Change i32 as exit code to u8
This avoids nasty surprises with negative numbers on some unix-alikes due to two's complement.
This commit is contained in:
@@ -87,9 +87,11 @@ pub enum ControlFlow {
|
|||||||
WaitUntil(Instant),
|
WaitUntil(Instant),
|
||||||
/// Send a `LoopDestroyed` event and stop the event loop. This variant is *sticky* - once set,
|
/// Send a `LoopDestroyed` event and stop the event loop. This variant is *sticky* - once set,
|
||||||
/// `control_flow` cannot be changed from `Exit`, and any future attempts to do so will result
|
/// `control_flow` cannot be changed from `Exit`, and any future attempts to do so will result
|
||||||
/// in the `control_flow` parameter being reset to `Exit`. The contained number will be used as
|
/// in the `control_flow` parameter being reset to `Exit`.
|
||||||
/// exit code, if the platform supports that (this means _not_ ios, android and wasm32).
|
/// The contained number will be used as exit code, if the platform supports that (this
|
||||||
Exit(i32),
|
/// _excludes_ ios, android and wasm32), it's an [`u8`] to prevent some weird surprises as
|
||||||
|
/// described in [`std::process::exit`].
|
||||||
|
Exit(u8),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for ControlFlow {
|
impl Default for ControlFlow {
|
||||||
|
|||||||
@@ -22,7 +22,8 @@ pub trait EventLoopExtRunReturn {
|
|||||||
/// Initializes the `winit` event loop.
|
/// Initializes the `winit` event loop.
|
||||||
///
|
///
|
||||||
/// Unlike `run`, this function accepts non-`'static` (i.e. non-`move`) closures and returns
|
/// Unlike `run`, this function accepts non-`'static` (i.e. non-`move`) closures and returns
|
||||||
/// control flow to the caller when `control_flow` is set to `ControlFlow::Exit`.
|
/// control flow to the caller when `control_flow` is set to `ControlFlow::Exit`, where its
|
||||||
|
/// content representing the exit code is the return value.
|
||||||
///
|
///
|
||||||
/// # Caveats
|
/// # Caveats
|
||||||
/// Despite its appearance at first glance, this is *not* a perfect replacement for
|
/// Despite its appearance at first glance, this is *not* a perfect replacement for
|
||||||
@@ -33,7 +34,7 @@ pub trait EventLoopExtRunReturn {
|
|||||||
/// underlying OS APIs, which cannot be hidden by `winit` without severe stability repercussions.
|
/// underlying OS APIs, which cannot be hidden by `winit` without severe stability repercussions.
|
||||||
///
|
///
|
||||||
/// You are strongly encouraged to use `run`, unless the use of this is absolutely necessary.
|
/// You are strongly encouraged to use `run`, unless the use of this is absolutely necessary.
|
||||||
fn run_return<F>(&mut self, event_handler: F) -> i32
|
fn run_return<F>(&mut self, event_handler: F) -> u8
|
||||||
where
|
where
|
||||||
F: FnMut(
|
F: FnMut(
|
||||||
Event<'_, Self::UserEvent>,
|
Event<'_, Self::UserEvent>,
|
||||||
@@ -45,7 +46,7 @@ pub trait EventLoopExtRunReturn {
|
|||||||
impl<T> EventLoopExtRunReturn for EventLoop<T> {
|
impl<T> EventLoopExtRunReturn for EventLoop<T> {
|
||||||
type UserEvent = T;
|
type UserEvent = T;
|
||||||
|
|
||||||
fn run_return<F>(&mut self, event_handler: F) -> i32
|
fn run_return<F>(&mut self, event_handler: F) -> u8
|
||||||
where
|
where
|
||||||
F: FnMut(
|
F: FnMut(
|
||||||
Event<'_, Self::UserEvent>,
|
Event<'_, Self::UserEvent>,
|
||||||
|
|||||||
@@ -655,7 +655,7 @@ impl<T: 'static> EventLoop<T> {
|
|||||||
x11_or_wayland!(match self; EventLoop(evlp) => evlp.create_proxy(); as EventLoopProxy)
|
x11_or_wayland!(match self; EventLoop(evlp) => evlp.create_proxy(); as EventLoopProxy)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn run_return<F>(&mut self, callback: F) -> i32
|
pub fn run_return<F>(&mut self, callback: F) -> u8
|
||||||
where
|
where
|
||||||
F: FnMut(crate::event::Event<'_, T>, &RootELW<T>, &mut ControlFlow),
|
F: FnMut(crate::event::Event<'_, T>, &RootELW<T>, &mut ControlFlow),
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -207,10 +207,10 @@ impl<T: 'static> EventLoop<T> {
|
|||||||
F: FnMut(Event<'_, T>, &RootEventLoopWindowTarget<T>, &mut ControlFlow) + 'static,
|
F: FnMut(Event<'_, T>, &RootEventLoopWindowTarget<T>, &mut ControlFlow) + 'static,
|
||||||
{
|
{
|
||||||
let exit_code = self.run_return(callback);
|
let exit_code = self.run_return(callback);
|
||||||
process::exit(exit_code);
|
process::exit(i32::from(exit_code));
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn run_return<F>(&mut self, mut callback: F) -> i32
|
pub fn run_return<F>(&mut self, mut callback: F) -> u8
|
||||||
where
|
where
|
||||||
F: FnMut(Event<'_, T>, &RootEventLoopWindowTarget<T>, &mut ControlFlow),
|
F: FnMut(Event<'_, T>, &RootEventLoopWindowTarget<T>, &mut ControlFlow),
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -258,7 +258,7 @@ impl<T: 'static> EventLoop<T> {
|
|||||||
&self.target
|
&self.target
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn run_return<F>(&mut self, mut callback: F) -> i32
|
pub fn run_return<F>(&mut self, mut callback: F) -> u8
|
||||||
where
|
where
|
||||||
F: FnMut(Event<'_, T>, &RootELW<T>, &mut ControlFlow),
|
F: FnMut(Event<'_, T>, &RootELW<T>, &mut ControlFlow),
|
||||||
{
|
{
|
||||||
@@ -391,7 +391,7 @@ impl<T: 'static> EventLoop<T> {
|
|||||||
F: 'static + FnMut(Event<'_, T>, &RootELW<T>, &mut ControlFlow),
|
F: 'static + FnMut(Event<'_, T>, &RootELW<T>, &mut ControlFlow),
|
||||||
{
|
{
|
||||||
let exit_code = self.run_return(callback);
|
let exit_code = self.run_return(callback);
|
||||||
::std::process::exit(exit_code);
|
::std::process::exit(i32::from(exit_code));
|
||||||
}
|
}
|
||||||
|
|
||||||
fn drain_events<F>(&mut self, callback: &mut F, control_flow: &mut ControlFlow)
|
fn drain_events<F>(&mut self, callback: &mut F, control_flow: &mut ControlFlow)
|
||||||
|
|||||||
@@ -189,10 +189,10 @@ impl<T: 'static> EventLoop<T> {
|
|||||||
F: 'static + FnMut(Event<'_, T>, &RootELW<T>, &mut ControlFlow),
|
F: 'static + FnMut(Event<'_, T>, &RootELW<T>, &mut ControlFlow),
|
||||||
{
|
{
|
||||||
let exit_code = self.run_return(event_handler);
|
let exit_code = self.run_return(event_handler);
|
||||||
::std::process::exit(exit_code);
|
::std::process::exit(i32::from(exit_code));
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn run_return<F>(&mut self, mut event_handler: F) -> i32
|
pub fn run_return<F>(&mut self, mut event_handler: F) -> u8
|
||||||
where
|
where
|
||||||
F: FnMut(Event<'_, T>, &RootELW<T>, &mut ControlFlow),
|
F: FnMut(Event<'_, T>, &RootELW<T>, &mut ControlFlow),
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user