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

[feat] refactor InvokeResponse as a Rust Result #5640

Open
LucasJavaudin opened this issue Nov 17, 2022 · 0 comments
Open

[feat] refactor InvokeResponse as a Rust Result #5640

LucasJavaudin opened this issue Nov 17, 2022 · 0 comments

Comments

@LucasJavaudin
Copy link
Contributor

Describe the problem

In the tauri/src/hooks.rs, InvokeResponse is defined as an enum with two variants Ok and Err, which is equivalent to the Rust Result type. Not using directly a Result adds complexity to the code as it requires to implement many conversion from and into Result for InvokeResponse.

Describe the solution you'd like

The definition of InvokeResponse could be replaced by pub struct InvokeResponse(Result<JsonValue, InvokeError>);.
The commit 7db6a27 shows how such a refactoring would look like.

Alternatives considered

The definition of InvokeResponse could instead be replaced by pub type InvokeResponse = Result<JsonValue, InvokeError>; but this means that converting From<Result<T, InvokeError>> for InvokeResponse to InvokeResponse would be more complex than a simple call to into or from (because we cannot write impl for defined types).

Additional context

This complexity can lead to unoptimized cost. For example, PR #5639 fixes a bug where a JsonValue was serialized into a JsonValue uselessly because of the conversion from Result to InvokeResponse.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: 📬Proposal
Development

No branches or pull requests

1 participant