Struct String

Source
pub struct String<'env> { /* private fields */ }
Expand description

A type representing a Java String.

Implementations§

Source§

impl<'env> String<'env>

Source

pub fn empty<'a>( env: &'a JniEnv<'a>, token: &NoException<'a>, ) -> JavaResult<'a, String<'a>>

Create a new empty string.

JNI documentation

Source

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.

JNI documentation

Source

pub fn len(&self, _token: &NoException<'_>) -> usize

String length (the number of unicode characters).

JNI documentation

Source

pub fn size(&self, _token: &NoException<'_>) -> usize

String size (the number of bytes in modified UTF-8).

JNI documentation

Source

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.

JNI documentation

Source§

impl<'env> String<'env>

Source

pub fn get_class( env: &'env JniEnv<'env>, token: &NoException<'env>, ) -> JavaResult<'env, Class<'env>>

Get the Java class object for String .

Object::getClass javadoc

Source§

impl<'env> String<'env>

Source

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.

JNI documentation

Source

pub fn to_string( &self, token: &NoException<'env>, ) -> JavaResult<'env, String<'env>>

Convert the object to a string.

Object::toString javadoc

Source

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.

String::valueOf(int) javadoc

Methods from Deref<Target = Object<'env>>§

Source

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.

Source

pub fn env(&self) -> &'env JniEnv<'env>

Get the JniEnv this object is bound to.

Source

pub fn class(&self, _token: &NoException<'_>) -> Class<'env>

Get the object’s class.

JNI documentation

Source

pub fn is_same_as(&self, other: &Object<'_>, _token: &NoException<'_>) -> bool

Compare with another Java object by reference.

JNI documentation

Source

pub fn is_instance_of( &self, class: &Class<'_>, _token: &NoException<'_>, ) -> bool

Check if the object is an instance of the class.

JNI documentation

Source

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.

JNI documentation

Source

pub fn to_string( &self, token: &NoException<'env>, ) -> JavaResult<'env, String<'env>>

Convert the object to a string.

Object::toString javadoc

Source

pub fn equals( &self, other: &Object<'_>, token: &NoException<'env>, ) -> JavaResult<'env, bool>

Compare to another Java object.

Object::equals

Trait Implementations§

Source§

impl<'env> Cast<'env, Object<'env>> for String<'env>

Make String castable to Object.

Source§

fn cast<'a>(&'a self) -> &'a Object<'env>

Cast the object to itself or one of it’s superclasses. Read more
Source§

impl<'env> Cast<'env, String<'env>> for String<'env>

Make String castable to itself.

Source§

fn cast<'a>(&'a self) -> &'a String<'env>

Cast the object to itself or one of it’s superclasses. Read more
Source§

impl<'env> Debug for String<'env>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'env> Deref for String<'env>

Allow String to be used in place of an Object.

Source§

type Target = Object<'env>

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl<'env> Display for String<'env>

Allow displaying String .

Object::toString javadoc

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§

fn fmt(&self, formatter: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'env, T> PartialEq<T> for String<'env>
where T: Cast<'env, Object<'env>>,

Allow comparing String to Java objects. Java objects are compared by-reference to preserve original Java semantics. To compare objects by value, call the equals method.

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.

Source§

fn eq(&self, other: &T) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<'env> Eq for String<'env>

Allow comparing String to Java objects. Java objects are compared by-reference to preserve original Java semantics. To compare objects by value, call the equals method.

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.

Source§

impl<'a> JavaType for String<'a>

Make String mappable to jobject.

Auto Trait Implementations§

§

impl<'env> Freeze for String<'env>

§

impl<'env> !RefUnwindSafe for String<'env>

§

impl<'env> !Send for String<'env>

§

impl<'env> !Sync for String<'env>

§

impl<'env> Unpin for String<'env>

§

impl<'env> !UnwindSafe for String<'env>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.