Skip to content

Add non-panicking try_* variants of the context functions - #8

Open
LucaCappelletti94 wants to merge 8 commits into
rust-mobile:masterfrom
LucaCappelletti94:upstream/ndk-context-non-panicking
Open

LucaCappelletti94 wants to merge 8 commits into
rust-mobile:masterfrom
LucaCappelletti94:upstream/ndk-context-non-panicking

Conversation

@LucaCappelletti94

@LucaCappelletti94 LucaCappelletti94 commented Sep 27, 2026 •

Copy link
Copy Markdown

Stacked on #6, so only the last commit belongs here.

Adds try_android_context(), try_initialize_android_context() and try_release_android_context(), as asked in #3, #4, #5 and rust-mobile/ndk#517. Crates currently probe the context with catch_unwind (rama, netdev, tauri-plugin-blec) or wrap the initialisation in it (iotzio, jni-min-helper), which cannot catch anything under panic = "abort". Dioxus guards its call with a Once because a second initialisation aborts.

A second initialisation keeps the first context and returns it. The existing functions keep their signatures and now wrap these, so a second initialize_android_context() keeps the first context and panics with android context was already initialized.

I am unsure whether it could be desirable to entirely remove the panicking function.

@LucaCappelletti94
LucaCappelletti94 marked this pull request as draft September 27, 2026 19:42
@LucaCappelletti94
LucaCappelletti94 force-pushed the upstream/ndk-context-non-panicking branch from 18bc6a2 to 9698d16 Compare September 27, 2026 19:45
@LucaCappelletti94 LucaCappelletti94 changed the title Add non-panicking try_ variants of the context functions Add non-panicking try_ variants of the context functions Sep 27, 2026
@LucaCappelletti94
LucaCappelletti94 marked this pull request as ready for review September 27, 2026 19:54
@LucaCappelletti94 LucaCappelletti94 changed the title Add non-panicking try_ variants of the context functions Add non-panicking try_* variants of the context functions Sep 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant