JavaStr

Struct JavaStr 

Source
pub struct JavaStr { /* private fields */ }
Expand description

A Java CESU-8 encoded string slice.

Implementations§

Source§

impl JavaStr

Source

pub const fn from_java_cesu8(v: &[u8]) -> Result<&JavaStr, EncodingError>

Converts a slice of bytes to a JavaStr.

A Java CESU-8 string slice (JavaStr) is made of bytes (u8), and a byte slice ([u8]) is made of bytes, so this function converts betwen the two. Not all byte slices are valid string slices, however JavaStr requires that it is valid Java CESU-8. from_java_cesu8 checks to ensure that the bytes are valid Java CESU-8, and then does the conversion.

If you are sure that the byte slice is valid Java CESU-8, and you don’t want to incur the overhead of the validity check, there is an unsafe version of this function from_java_cesu8_unchecked, which has the same behavior but skips the check.

§Errors

Returns Err if the slice is not Java CESU-8 with a description as to why the provided slice is not Java CESU-8.

Source

pub fn from_java_cesu8_mut(v: &mut [u8]) -> Result<&mut JavaStr, EncodingError>

Converts a mutable slice of bytes to a mutable JavaStr.

A Java CESU-8 string slice (JavaStr) is made of bytes (u8), and a byte slice ([u8]) is made of bytes, so this function converts betwen the two. Not all byte slices are valid string slices, however JavaStr requires that it is valid Java CESU-8. from_java_cesu8 checks to ensure that the bytes are valid Java CESU-8, and then does the conversion.

If you are sure that the byte slice is valid Java CESU-8, and you don’t want to incur the overhead of the validity check, there is an unsafe version of this function from_java_cesu8_unchecked_mut, which has the same behavior but skips the check.

§Errors

Returns Err if the slice is not Java CESU-8 with a description as to why the provided slice is not Java CESU-8.

Source

pub const unsafe fn from_java_cesu8_unchecked(v: &[u8]) -> &JavaStr

Converts a slice of bytes to a JavaStr without checking that the string contains valid Java CESU-8.

See the safe version, from_java_cesu8, for more details.

§Safety

The bytes passed in must be valid Java CESU-8.

Source

pub unsafe fn from_java_cesu8_unchecked_mut(v: &mut [u8]) -> &mut JavaStr

Converts a mutable slice of bytes to a mutable JavaStr without checking that the string contains valid Java CESU-8.

See the safe version, from_java_cesu8_mut, for more details.

§Safety

The bytes passed in must be valid Java CESU-8.

Source

pub unsafe fn from_boxed_java_cesu8_unchecked(v: Box<[u8]>) -> Box<JavaStr>

Converts a boxed slice of bytes to a boxed string slice without checking that the string contains valid Java CESU-8.

§Safety

The bytes passed in must be valid Java CESU-8.

Source

pub const fn len(&self) -> usize

Returns the length of self.

This length is in bytes, not chars or graphemes. In other words, it might not be what a human considers the length of the string.

Source

pub const fn is_empty(&self) -> bool

Returns true if self has a length of zero bytes.

Source

pub fn is_char_boundary(&self, index: usize) -> bool

Checks that the index-th byte is the first byte in a Java CESU-8 code point sequence or the end of the string.

The start and end of the string (when index == self.len()) are considered to be boundaries.

Returns false if index is greater than self.len().

Source

pub const fn as_bytes(&self) -> &[u8]

Converts a string slice to a byte slice.

Source

pub unsafe fn as_bytes_mut(&mut self) -> &mut [u8]

Converts a mutable string slice to a mutable byte slice.

§Safety

The caller must ensure that the content of the slice is valid Java CESU-8 before the borrow ends and the underlying JavaStr is used.

Use of a JavaStr whose contents are not valid Java CESU-8 is undefined behavior.

Source

pub const fn as_ptr(&self) -> *const u8

Converts a string slice to a raw pointer.

As string slices are a slice of bytes, the raw pointer points to a u8. This pointer will be pointing to the first bytes of the string slice.

The caller must ensure that the returned pointer is never written to. If you need to mutate the contents of the string slice, use as_mut_ptr.

Source

pub fn as_mut_ptr(&mut self) -> *mut u8

Converts a mutable string slice to a raw pointer.

As string slices are a slice of bytes, the raw pointer points to a u8. This pointer will be pointing to the first byte of the string slice.

It is your responsibility to make sure that the string slice only gets modified in a way that it remains valid Java CESU-8.

Source

pub fn get<I: RangeBounds<usize>>(&self, index: I) -> Option<&JavaStr>

Returns a subslice of JavaStr.

This is the non-panicking alternative to indexing the str. Returns None whenever equivalent indexing operations would panic.

Source

pub fn get_mut<I: RangeBounds<usize>>( &mut self, index: I, ) -> Option<&mut JavaStr>

Returns a mutable subslice of JavaStr.

This is the non-panicking alternative to indexing the JavaStr. Returns None whenver equivalent indexing operations would panic.

Source

pub unsafe fn get_unchecked<I: RangeBounds<usize>>(&self, index: I) -> &JavaStr

Returns an unchecked subslice of JavaStr.

This is the unchecked alternative to indexing the JavaStr.

§Safety

Callers of this function are responsible for ensuring that:

  • The starting index does not exceed the ending index;
  • The indices are within the bounds of the original slice;
  • The indices fall on Java CESU-8 sequence boundaries.

Failing that, the returned string slice may reference invalid memory or violate the invariants communicated by the JavaStr type.

Source

pub unsafe fn get_unchecked_mut<I: RangeBounds<usize>>( &mut self, index: I, ) -> &mut JavaStr

Returns a mutable, unchecked subslice of JavaStr.

This the unchecked alternative to indexing the JavaStr.

§Safety

Callers of this function are responsible for ensuring that:

  • The starting index does not exceed the ending index;
  • The indices are within the bounds of the original slice;
  • The indices fall on Java CESU-8 sequence boundaries.

Failing that, the returned string slice may reference invalid memory or violate the invariants communicated by the JavaStr type.

Source

pub fn split_at(&self, mid: usize) -> (&JavaStr, &JavaStr)

Divide one string slice into two at an index.

The argument, mid, should be a byte offset from the start of the string. It must also be on the boundary of a Java CESU-8 character.

The two slices returned go from the string of the string slice to mid, and from mid to the end of the string slice.

To get mutable string slices instead, see the split_at_mut method.

Source

pub fn split_at_mut(&mut self, mid: usize) -> (&mut JavaStr, &mut JavaStr)

Divide one mutable string slice into two at an index.

The argument, mid, should be a byte offset from the start of the string. It must also be on the boundary of a Java CESU-8 character.

The two slices returned go from the string of the string slice to mid, and from mid to the end of the string slice.

To get immutable string slices instead, see the split_at method.

Source

pub fn split_at_checked(&self, mid: usize) -> Option<(&JavaStr, &JavaStr)>

Divide one string slice into two at an index.

The argument, mid, should be a valid byte offset from the start of the string. It must also be on the boundary of a Java CESU-8 code point. The method returns None if that’s not the case.

The two slices returned go from the start of the string slice to mid, and from mid to the end of the string slice.

To get mutable string slices instead, see the split_at_mut_checked method.

Source

pub fn split_at_mut_checked( &mut self, mid: usize, ) -> Option<(&mut JavaStr, &mut JavaStr)>

Divide one mutable string slice into two at an index.

The argument, mid, should be a valid byte offset from the start of the string. It must also be on the boundary of a Java CESU-8 code point. The method returns None if that’s not the case.

The two slices returned go from the start of the string slice to mid, and from mid to the end of the string slice.

To get immutable string slices instead, see the split_at_checked method.

Source

pub unsafe fn split_at_unchecked(&self, mid: usize) -> (&JavaStr, &JavaStr)

Divide a string into two at an index.

The two slices returned go from the start of the string slice to mid, and from mid to the end of the string slice.

To get mutable string slices instead, see the split_at_mut_unchecked method.

§Safety

The caller must ensure that mid is a valid byte offset from the start of the string and falls on the boundary of a Java CESU-8 character.

Source

pub unsafe fn split_at_mut_unchecked( &mut self, mid: usize, ) -> (&mut JavaStr, &mut JavaStr)

Divide a mutable string into two at an index.

The two slices returned go from the start of the string slice to mid, and from mid to the end of the string slice.

To get immutable string slices instead, see the split_at_unchecked method.

§Safety

The caller must ensure that mid is a valid byte offset from the start of the string and falls on the boundary of a Java CESU-8 character.

Source

pub fn chars(&self) -> JavaChars<'_>

Returns an iterator over the chars of a string slice.

As an JavaStr consists of valid Java CESU-8, we can iterate through a string by char. This method returns such an iterator.

It’s important to remember that char represents a Unicode Scalar Value, and might not match your idea of what a ‘character’ is. Iteration over grapheme clusters may be what you actually want. This functionality is not provided by this crate.

Source

pub fn char_indices(&self) -> JavaCharIndices<'_>

Returns an iterator over the chars of a string slice, and their positions.

As an JavaStr consists of valid Java CESU-8, we can iterate through a string by char. This method returns an iterator of both these chars, as well as their byte positions.

The iterator yields tuples. The position is first, the char is second.

Source

pub const fn is_ascii(&self) -> bool

Checks if all characters in this string are within the ASCII range.

Trait Implementations§

Source§

impl AsRef<[u8]> for JavaStr

Source§

fn as_ref(&self) -> &[u8]

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl Borrow<JavaStr> for JavaString

Source§

fn borrow(&self) -> &JavaStr

Immutably borrows from an owned value. Read more
Source§

impl Debug for JavaStr

Source§

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

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

impl Display for JavaStr

Source§

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

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

impl Hash for JavaStr

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
Source§

impl Index<Range<usize>> for &JavaStr

Source§

type Output = JavaStr

The returned type after indexing.
Source§

fn index(&self, index: Range<usize>) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl Index<Range<usize>> for &mut JavaStr

Source§

type Output = JavaStr

The returned type after indexing.
Source§

fn index(&self, index: Range<usize>) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl Index<Range<usize>> for JavaStr

Source§

type Output = JavaStr

The returned type after indexing.
Source§

fn index(&self, index: Range<usize>) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl Index<RangeFrom<usize>> for &JavaStr

Source§

type Output = JavaStr

The returned type after indexing.
Source§

fn index(&self, index: RangeFrom<usize>) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl Index<RangeFrom<usize>> for &mut JavaStr

Source§

type Output = JavaStr

The returned type after indexing.
Source§

fn index(&self, index: RangeFrom<usize>) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl Index<RangeFrom<usize>> for JavaStr

Source§

type Output = JavaStr

The returned type after indexing.
Source§

fn index(&self, index: RangeFrom<usize>) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl Index<RangeFull> for &JavaStr

Source§

type Output = JavaStr

The returned type after indexing.
Source§

fn index(&self, index: RangeFull) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl Index<RangeFull> for &mut JavaStr

Source§

type Output = JavaStr

The returned type after indexing.
Source§

fn index(&self, index: RangeFull) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl Index<RangeFull> for JavaStr

Source§

type Output = JavaStr

The returned type after indexing.
Source§

fn index(&self, index: RangeFull) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl Index<RangeInclusive<usize>> for &JavaStr

Source§

type Output = JavaStr

The returned type after indexing.
Source§

fn index(&self, index: RangeInclusive<usize>) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl Index<RangeInclusive<usize>> for &mut JavaStr

Source§

type Output = JavaStr

The returned type after indexing.
Source§

fn index(&self, index: RangeInclusive<usize>) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl Index<RangeInclusive<usize>> for JavaStr

Source§

type Output = JavaStr

The returned type after indexing.
Source§

fn index(&self, index: RangeInclusive<usize>) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl Index<RangeTo<usize>> for &JavaStr

Source§

type Output = JavaStr

The returned type after indexing.
Source§

fn index(&self, index: RangeTo<usize>) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl Index<RangeTo<usize>> for &mut JavaStr

Source§

type Output = JavaStr

The returned type after indexing.
Source§

fn index(&self, index: RangeTo<usize>) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl Index<RangeTo<usize>> for JavaStr

Source§

type Output = JavaStr

The returned type after indexing.
Source§

fn index(&self, index: RangeTo<usize>) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl Index<RangeToInclusive<usize>> for &JavaStr

Source§

type Output = JavaStr

The returned type after indexing.
Source§

fn index(&self, index: RangeToInclusive<usize>) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl Index<RangeToInclusive<usize>> for &mut JavaStr

Source§

type Output = JavaStr

The returned type after indexing.
Source§

fn index(&self, index: RangeToInclusive<usize>) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl Index<RangeToInclusive<usize>> for JavaStr

Source§

type Output = JavaStr

The returned type after indexing.
Source§

fn index(&self, index: RangeToInclusive<usize>) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl IndexMut<Range<usize>> for &mut JavaStr

Source§

fn index_mut(&mut self, index: Range<usize>) -> &mut Self::Output

Performs the mutable indexing (container[index]) operation. Read more
Source§

impl IndexMut<Range<usize>> for JavaStr

Source§

fn index_mut(&mut self, index: Range<usize>) -> &mut Self::Output

Performs the mutable indexing (container[index]) operation. Read more
Source§

impl IndexMut<RangeFrom<usize>> for &mut JavaStr

Source§

fn index_mut(&mut self, index: RangeFrom<usize>) -> &mut Self::Output

Performs the mutable indexing (container[index]) operation. Read more
Source§

impl IndexMut<RangeFrom<usize>> for JavaStr

Source§

fn index_mut(&mut self, index: RangeFrom<usize>) -> &mut Self::Output

Performs the mutable indexing (container[index]) operation. Read more
Source§

impl IndexMut<RangeFull> for &mut JavaStr

Source§

fn index_mut(&mut self, index: RangeFull) -> &mut Self::Output

Performs the mutable indexing (container[index]) operation. Read more
Source§

impl IndexMut<RangeFull> for JavaStr

Source§

fn index_mut(&mut self, index: RangeFull) -> &mut Self::Output

Performs the mutable indexing (container[index]) operation. Read more
Source§

impl IndexMut<RangeInclusive<usize>> for &mut JavaStr

Source§

fn index_mut(&mut self, index: RangeInclusive<usize>) -> &mut Self::Output

Performs the mutable indexing (container[index]) operation. Read more
Source§

impl IndexMut<RangeInclusive<usize>> for JavaStr

Source§

fn index_mut(&mut self, index: RangeInclusive<usize>) -> &mut Self::Output

Performs the mutable indexing (container[index]) operation. Read more
Source§

impl IndexMut<RangeTo<usize>> for &mut JavaStr

Source§

fn index_mut(&mut self, index: RangeTo<usize>) -> &mut Self::Output

Performs the mutable indexing (container[index]) operation. Read more
Source§

impl IndexMut<RangeTo<usize>> for JavaStr

Source§

fn index_mut(&mut self, index: RangeTo<usize>) -> &mut Self::Output

Performs the mutable indexing (container[index]) operation. Read more
Source§

impl IndexMut<RangeToInclusive<usize>> for &mut JavaStr

Source§

fn index_mut(&mut self, index: RangeToInclusive<usize>) -> &mut Self::Output

Performs the mutable indexing (container[index]) operation. Read more
Source§

impl IndexMut<RangeToInclusive<usize>> for JavaStr

Source§

fn index_mut(&mut self, index: RangeToInclusive<usize>) -> &mut Self::Output

Performs the mutable indexing (container[index]) operation. Read more
Source§

impl Ord for JavaStr

Source§

fn cmp(&self, other: &JavaStr) -> Ordering

This method returns an Ordering between self and other. Read more
Source§

impl PartialEq for JavaStr

Source§

fn eq(&self, other: &JavaStr) -> 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 PartialOrd for JavaStr

Source§

fn partial_cmp(&self, other: &JavaStr) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

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

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

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

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

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

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl ToOwned for JavaStr

Available on crate feature alloc only.
Source§

type Owned = JavaString

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> Self::Owned

Creates owned data from borrowed data, usually by cloning. Read more
1.63.0 · Source§

fn clone_into(&self, target: &mut Self::Owned)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl Eq for JavaStr

Source§

impl StructuralPartialEq for JavaStr

Auto Trait Implementations§

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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more