pub struct String<'env> { /* private fields */ }
Expand description
A type representing a Java
String
.
Implementations§
Source§impl<'env> String<'env>
impl<'env> String<'env>
Sourcepub fn empty<'a>(
env: &'a JniEnv<'a>,
token: &NoException<'a>,
) -> JavaResult<'a, String<'a>>
pub fn empty<'a>( env: &'a JniEnv<'a>, token: &NoException<'a>, ) -> JavaResult<'a, String<'a>>
Create a new empty string.
Sourcepub fn new<'a>(
env: &'a JniEnv<'a>,
string: &str,
token: &NoException<'a>,
) -> JavaResult<'a, String<'a>>
pub fn new<'a>( env: &'a JniEnv<'a>, string: &str, token: &NoException<'a>, ) -> JavaResult<'a, String<'a>>
Create a new Java string from a Rust string.
Sourcepub fn len(&self, _token: &NoException<'_>) -> usize
pub fn len(&self, _token: &NoException<'_>) -> usize
String length (the number of unicode characters).
Sourcepub fn size(&self, _token: &NoException<'_>) -> usize
pub fn size(&self, _token: &NoException<'_>) -> usize
String size (the number of bytes in modified UTF-8).
Sourcepub fn as_string(&self, token: &NoException<'_>) -> String
pub fn as_string(&self, token: &NoException<'_>) -> String
Convert the Java String
into a Rust String
.
This method has a different signature from the one in the ToString
trait because
extracting bytes from String
is only safe when there is no pending exception.
Source§impl<'env> String<'env>
impl<'env> String<'env>
Sourcepub fn get_class(
env: &'env JniEnv<'env>,
token: &NoException<'env>,
) -> JavaResult<'env, Class<'env>>
pub fn get_class( env: &'env JniEnv<'env>, token: &NoException<'env>, ) -> JavaResult<'env, Class<'env>>
Get the Java class object for
String
.
Source§impl<'env> String<'env>
impl<'env> String<'env>
Sourcepub fn clone(&self, token: &NoException<'env>) -> JavaResult<'env, Self>where
Self: Sized,
pub fn clone(&self, token: &NoException<'env>) -> JavaResult<'env, Self>where
Self: Sized,
Clone the
String
. This is not a deep clone of the Java object,
but a Rust-like clone of the value. Since Java objects are reference counted, this
will increment the reference count.
This method has a different signature from the one in the
Clone
trait
because cloning a Java object is only safe when there is no pending exception and
because cloning a java object cat throw an exception.
Sourcepub fn to_string(
&self,
token: &NoException<'env>,
) -> JavaResult<'env, String<'env>>
pub fn to_string( &self, token: &NoException<'env>, ) -> JavaResult<'env, String<'env>>
Convert the object to a string.
Sourcepub fn value_of_int(
env: &'env JniEnv<'env>,
value: i32,
token: &NoException<'env>,
) -> JavaResult<'env, String<'env>>
pub fn value_of_int( env: &'env JniEnv<'env>, value: i32, token: &NoException<'env>, ) -> JavaResult<'env, String<'env>>
Get the string value of an integer.
Methods from Deref<Target = Object<'env>>§
Sourcepub unsafe fn raw_object(&self) -> jobject
pub unsafe fn raw_object(&self) -> jobject
Get the raw object pointer.
This function provides low-level access to the Java object and thus is unsafe.
Sourcepub fn class(&self, _token: &NoException<'_>) -> Class<'env>
pub fn class(&self, _token: &NoException<'_>) -> Class<'env>
Get the object’s class.
Sourcepub fn is_same_as(&self, other: &Object<'_>, _token: &NoException<'_>) -> bool
pub fn is_same_as(&self, other: &Object<'_>, _token: &NoException<'_>) -> bool
Compare with another Java object by reference.
Sourcepub fn is_instance_of(
&self,
class: &Class<'_>,
_token: &NoException<'_>,
) -> bool
pub fn is_instance_of( &self, class: &Class<'_>, _token: &NoException<'_>, ) -> bool
Check if the object is an instance of the class.
Sourcepub fn clone(&self, token: &NoException<'env>) -> JavaResult<'env, Object<'env>>
pub fn clone(&self, token: &NoException<'env>) -> JavaResult<'env, Object<'env>>
Clone the Object
. This is not a deep clone of the Java object,
but a Rust-like clone of the value. Since Java objects are reference counted, this will
increment the reference count.
This method has a different signature from the one in the
Clone
trait because
cloning a Java object is only safe when there is no pending exception and because
cloning a java object cat throw an exception.
Sourcepub fn to_string(
&self,
token: &NoException<'env>,
) -> JavaResult<'env, String<'env>>
pub fn to_string( &self, token: &NoException<'env>, ) -> JavaResult<'env, String<'env>>
Convert the object to a string.
Sourcepub fn equals(
&self,
other: &Object<'_>,
token: &NoException<'env>,
) -> JavaResult<'env, bool>
pub fn equals( &self, other: &Object<'_>, token: &NoException<'env>, ) -> JavaResult<'env, bool>
Compare to another Java object.
Trait Implementations§
Source§impl<'env> Display for String<'env>
Allow displaying
String
.
impl<'env> Display for String<'env>
Allow displaying
String
.
This is mostly a convenience for debugging. Always prefer using
to_string
to printing the object as is, because
the former checks for a pending exception in compile-time rather than the run-time.
Source§impl<'env, T> PartialEq<T> for String<'env>
impl<'env, T> PartialEq<T> for String<'env>
Will panic if there is a pending exception in the current thread.
This is mostly a convenience for using assert_eq!()
in tests. Always prefer using
is_same_as
to comparing with ==
, because
the former checks for a pending exception in compile-time rather than the run-time.
impl<'env> Eq for String<'env>
Will panic if there is a pending exception in the current thread.
This is mostly a convenience for using assert_eq!()
in tests. Always prefer using
is_same_as
to comparing with ==
, because
the former checks for a pending exception in compile-time rather than the run-time.