Skip to content

Commit 006d76e

Browse files
committed
feat: builtin conversions for &str as well
1 parent 78b57d6 commit 006d76e

File tree

3 files changed

+8
-9
lines changed

3 files changed

+8
-9
lines changed

macro/src/attrs.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ pub(crate) struct AttrsOptions {
88
}
99

1010
impl AttrsOptions {
11-
1211
pub(crate) fn parse_attr(attrs: TokenStream) -> Result<Self, syn::Error> {
1312
let mut what_next = WhatNext::Nothing;
1413

macro/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ mod wrapper;
33
mod args;
44
mod ret;
55

6-
76
/// wrap this function in in a JNI exported fn
87
#[proc_macro_attribute]
98
pub fn jni(

src/lib.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ pub fn from_java_static<'j, T: FromJava<'j>>(env: &mut jni::JNIEnv<'j>, val: T::
2323

2424
pub trait FromJava<'j> : Sized {
2525
type T : Sized;
26-
2726
fn from_java(env: &mut jni::JNIEnv<'j>, value: Self::T) -> Result<Self, jni::errors::Error>;
2827
}
2928

@@ -73,9 +72,6 @@ impl<'j, T: FromJava<'j, T = jni::objects::JObject<'j>>> FromJava<'j> for Option
7372
}
7473
}
7574

76-
77-
78-
7975
pub trait IntoJava<'j> {
8076
type T;
8177

@@ -110,14 +106,20 @@ impl<'j> IntoJava<'j> for bool {
110106
}
111107
}
112108

113-
impl<'j> IntoJava<'j> for String {
109+
impl<'j> IntoJava<'j> for &str {
114110
type T = jni::sys::jstring;
115-
116111
fn into_java(self, env: &mut jni::JNIEnv<'j>) -> Result<Self::T, jni::errors::Error> {
117112
Ok(env.new_string(self)?.as_raw())
118113
}
119114
}
120115

116+
impl<'j> IntoJava<'j> for String {
117+
type T = jni::sys::jstring;
118+
fn into_java(self, env: &mut jni::JNIEnv<'j>) -> Result<Self::T, jni::errors::Error> {
119+
self.as_str().into_java(env)
120+
}
121+
}
122+
121123
impl<'j> IntoJava<'j> for Vec<String> {
122124
type T = jni::sys::jobjectArray;
123125

@@ -139,5 +141,4 @@ impl<'j, T: IntoJava<'j, T = jni::sys::jobject>> IntoJava<'j> for Option<T> {
139141
None => Ok(std::ptr::null_mut()),
140142
}
141143
}
142-
143144
}

0 commit comments

Comments
 (0)