typed_jni/string/
mod.rs

1use alloc::string::String;
2
3use typed_jni_core::{JNIEnv, StrongRef};
4
5use crate::{LocalObject, Object, TypedRef, builtin::JavaString};
6
7/// Extension methods for typed string maintenance.
8pub trait TypedStringExt {
9    /// Creates a new string from the given string.
10    fn typed_new_string(&self, s: impl AsRef<str>) -> LocalObject<'_, JavaString>;
11
12    /// Returns the string slice of the given string object.
13    fn typed_get_string(&self, s: &Object<impl StrongRef, JavaString>) -> String;
14}
15
16impl<'vm> TypedStringExt for JNIEnv<'vm> {
17    fn typed_new_string(&self, s: impl AsRef<str>) -> LocalObject<'_, JavaString> {
18        unsafe { LocalObject::from_ref(self.new_string(s)) }
19    }
20
21    fn typed_get_string(&self, s: &Object<impl StrongRef, JavaString>) -> String {
22        unsafe { self.get_string(&**s) }
23    }
24}