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] Webview::navigate borrows &self instead of &mut self #12430

Closed
WSH032 opened this issue Jan 18, 2025 · 0 comments · Fixed by #12461
Closed

[feat] Webview::navigate borrows &self instead of &mut self #12430

WSH032 opened this issue Jan 18, 2025 · 0 comments · Fixed by #12461

Comments

@WSH032
Copy link
Contributor

WSH032 commented Jan 18, 2025

Describe the problem

/// Navigates the webview to the defined url.
pub fn navigate(&mut self, url: Url) -> crate::Result<()> {
self.webview.dispatcher.navigate(url).map_err(Into::into)
}

Currently, Webview::navigate borrows &mut self, but its underlying implementation tauri_runtime::WebviewDispatch::navigate only requires an immutable borrow &self.

Is there any specific reason why tauri::Webview needs to do this? If not, can we change it to only require an immutable borrow &self?


Why don't I want &mut self?

I am implementing Python bindings for Webview::navigate in pytauri: WSH032/pytauri#46.

Python is multithreaded, and when implementing pyo3 bindings for a Rust struct, if at least one method requires &mut self, we have to add a thread lock, which degrades performance.

As of now, except for navigate, other methods of Webview only require &self, and I don't want to add a thread lock just for only one method.

Describe the solution you'd like

just change WebviewWindow::navigate and Webview::navigate to &self.

Alternatives considered

None

Additional context

pyo3/Bound and interior mutability

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant