-
-
Notifications
You must be signed in to change notification settings - Fork 131
gio: Return glib::ExitCode
from gio::Application
signal handlers
#1694
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
Conversation
gio/src/application.rs
Outdated
} | ||
|
||
#[doc(alias = "handle-local-options")] | ||
fn connect_handle_local_options<F: Fn(&Self, &glib::VariantDict) -> ExitCode + 'static>( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we add another associated constant to glib::ExitCode
, e.g. glib::ExitCode::CONTINUE
? I dont feel comfortable with an enum
or e.g. Option
because Some(glib::ExitCode::from(-1))
and None
would be two representations for the effectively the same value.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just checked the documentation for the return value of the handle-local-options
signal.
An exit code. If you have handled your options and want to exit the process, return a non-negative option, 0 for success, and a positive value for failure. To continue, return -1 to let the default option processing continue.
It seems like the definition of glib::ExitCode
should be:
- positive means failure
- zero means success
- negative means special value
This means that I'm really not comfortable with the implementation of Termination
for glib::ExitCode
. Any value that does not fit into u8
shoudl probably be mapped to e.g. u8::MAX
.
I've pushed an additional commit that adds a glib::ExitCode::CONTINUE
associated constant and some initial documentation for the glib::ExitCode
struct.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems like the definition of glib::ExitCode should be:
That proposal only makes sense if the negative values have a meaning whenever they are used. As far as I have seen it is only a handful of fns that do something special with negative values. Please correct me if I am wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Like @A6GibKm says, the main problem here is that handle_local_options()
is special. It should probably have a different type than the other cases.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wouldn't like to have multiple representations for the same handling. If we'd use Option<glib::ExitCode>
there shouldn't be a way to say Some(glib::ExitCode::from(-1))
and None
which would lead to the same effect.
We could constrain the glib::ExitCode
type though.
- Remove
impl From<i32> for glib::ExitCode
- Add
impl From<u8> for glib::ExitCode
instead - Add
impl TryFrom<i32> for glib::ExitCode
- Add
struct InvalidExitCode(i32)
as theTryFrom::Error
type
We could then modify interfaces that currently return a glib::ExitCode
which may originate from foreign code, e.g. gio::ApplicationExtManual::run
to return a Result<glib::ExitCode, glib::InvalidExitCode>
instead. While we'd enforce good exit codes from Rust code through the traits and conversion methods. Using Option<glib::ExitCode>
or std::ops::ControlFlow<glib::ExitCode>
would then be fine for handle-local-options
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this implementation makes sense. @A6GibKm what do you think?
c7a63e0
to
e498ede
Compare
2bdf6e6
to
f99d9a6
Compare
I've now changed the One benefit of This required me to bump the MSRV to Using
|
f99d9a6
to
2cb2b35
Compare
caae6ea
to
0ba97c1
Compare
Add a manual override to use `glib::ExitCode` or `ControlFlow<glib::ExitCode>` instead of the gir generated `i32` return value for the `command-line` and `handle-local-options` signals as well as the `local_command_line` virtual function. This reworks the `ExitCode` type to only support `u8` values. The `From<i32>` implementation is replaced with a `TryFrom<i32>` implementation.
36c7e6c
to
218ed47
Compare
Let's get this in then |
@pjungkamp @sdroege While upgrading I came across this change and noticed that while this PR changes some parts of the command line API to use Shouldn't it now take |
@pjungkamp Maybe we can get around that by changing this to Alternatively could add a |
@sdroege Wrt to a PR, are you asking me or @pjungkamp? I can make a PR, but I'd not bother much with backwards compatibility, and just change the API right away. Then you can either release a quick 0.21.1 with this change; even though it's technically breaking, I doubt it has much practical impact, since it's a bit of a niche API, I guess. Or you just save the change for 0.22; effectively it only saves one |
I agree that the The Rust standard library uses the We could follow this naming convention in |
That sounds good to me. Do you want to provide a PR @pjungkamp ? |
Add a manual override to use
glib::ExitCode
instead of the gir generatedi32
return value forconnect_command_line
andconnect_handle_local_options
.This fixes #1691