Skip to content

Commit 25502fe

Browse files
committed
fixup: Borrow JNIEnv mutably
1 parent 079555c commit 25502fe

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

src/intent.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use jni::{
55
};
66

77
struct Inner<'env> {
8-
env: JNIEnv<'env>,
8+
env: &'env mut JNIEnv<'env>,
99
object: JObject<'env>,
1010
}
1111

@@ -16,7 +16,7 @@ pub struct Intent<'env> {
1616
}
1717

1818
impl<'env> Intent<'env> {
19-
pub fn from_object(env: JNIEnv<'env>, object: JObject<'env>) -> Self {
19+
pub fn from_object(env: &'env mut JNIEnv<'env>, object: JObject<'env>) -> Self {
2020
Self {
2121
inner: Ok(Inner { env, object }),
2222
}
@@ -27,7 +27,7 @@ impl<'env> Intent<'env> {
2727
Self { inner }
2828
}
2929

30-
pub fn new(mut env: JNIEnv<'env>, action: impl AsRef<str>) -> Self {
30+
pub fn new(env: &'env mut JNIEnv<'env>, action: impl AsRef<str>) -> Self {
3131
Self::from_fn(|| {
3232
let intent_class = env.find_class("android/content/Intent")?;
3333
let action_view =
@@ -47,7 +47,7 @@ impl<'env> Intent<'env> {
4747
}
4848

4949
pub fn new_with_uri(
50-
mut env: JNIEnv<'env>,
50+
env: &'env mut JNIEnv<'env>,
5151
action: impl AsRef<str>,
5252
uri: impl AsRef<str>,
5353
) -> Self {
@@ -93,7 +93,7 @@ impl<'env> Intent<'env> {
9393
package_name: impl AsRef<str>,
9494
class_name: impl AsRef<str>,
9595
) -> Self {
96-
self.and_then(|mut inner| {
96+
self.and_then(|inner| {
9797
let package_name = inner.env.new_string(package_name)?;
9898
let class_name = inner.env.new_string(class_name)?;
9999

@@ -118,7 +118,7 @@ impl<'env> Intent<'env> {
118118
/// # })
119119
/// ```
120120
pub fn with_extra(self, key: impl AsRef<str>, value: impl AsRef<str>) -> Self {
121-
self.and_then(|mut inner| {
121+
self.and_then(|inner| {
122122
let key = inner.env.new_string(key)?;
123123
let value = inner.env.new_string(value)?;
124124

@@ -177,7 +177,7 @@ impl<'env> Intent<'env> {
177177
/// # })
178178
/// ```
179179
pub fn with_type(self, type_name: impl AsRef<str>) -> Self {
180-
self.and_then(|mut inner| {
180+
self.and_then(|inner| {
181181
let jstring = inner.env.new_string(type_name)?;
182182

183183
inner.env.call_method(
@@ -195,7 +195,7 @@ impl<'env> Intent<'env> {
195195
let cx = ndk_context::android_context();
196196
let activity = unsafe { JObject::from_raw(cx.context() as jni::sys::jobject) };
197197

198-
self.inner.and_then(|mut inner| {
198+
self.inner.and_then(|inner| {
199199
inner.env.call_method(
200200
activity,
201201
"startActivity",

src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ pub use intent::Intent;
99
use jni::{JNIEnv, JavaVM};
1010

1111
/// Run 'f' with the current [`JNIEnv`] from [`ndk_context`].
12-
pub fn with_current_env(f: impl FnOnce(&JNIEnv<'_>)) {
12+
pub fn with_current_env(f: impl FnOnce(&mut JNIEnv)) {
1313
let cx = ndk_context::android_context();
1414
let vm = unsafe { JavaVM::from_raw(cx.vm().cast()) }.unwrap();
15-
let env = vm.attach_current_thread().unwrap();
15+
let mut env = vm.attach_current_thread().unwrap();
1616

17-
f(&env);
17+
f(&mut env);
1818
}

0 commit comments

Comments
 (0)