str32

Type Alias str32 

Source
pub type str32 = StringSlice<char>;
Expand description

Exactly the same as std::str, except generic

Aliased Type§

pub struct str32 { /* private fields */ }

Implementations§

Source§

impl str32

Source

pub fn len(&self) -> usize

Returns the length of self.

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

§Examples

Basic usage:

assert_eq!(String32::from("foo").len(), 3);
assert_eq!(String32::from("ƒoo").len(), 3); // fancy f!
Source

pub fn is_empty(&self) -> bool

Returns true if self has a length of zero bytes.

§Examples

Basic usage:

let s = String32::from("");
assert!(s.is_empty());

let s = String32::from("not empty");
assert!(!s.is_empty());
Source

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

Converts a string slice to a raw pointer.

As string slices are a slice of bytes, the raw pointer points to a char. This pointer will be pointing to the first byte 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.

§Examples

Basic usage:

let s = String32::from("Hello");
let ptr = s.as_ptr();
Source

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

Converts a mutable string slice to a raw pointer.

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

Source

pub fn from_slice(data: &[char]) -> &Self

Converts a mutable string slice to a raw pointer.

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

Source

pub fn from_slice_mut(data: &mut [char]) -> &mut Self

Converts a mutable string slice to a raw pointer.

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

Source

pub fn get<I: SliceIndex<Self>>(&self, i: I) -> Option<&I::Output>

Returns a subslice of str.

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

§Examples
let v = String32::from("🗻∈🌏");

assert_eq!(v.get(0..2).unwrap().to_owned(), String32::from("🗻∈"));

// out of bounds
assert!(v.get(..4).is_none());
Source

pub fn get_mut<I: SliceIndex<Self>>(&mut self, i: I) -> Option<&mut I::Output>

Returns a mutable subslice of str.

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

§Examples
let mut v = String32::from("hello");
// correct length
assert!(v.get_mut(0..5).is_some());
// out of bounds
assert!(v.get_mut(..42).is_none());

{
    let s = v.get_mut(0..2);
    let s = s.map(|s| {
        s.make_ascii_uppercase();
        &*s
    });
}
assert_eq!(v, String32::from("HEllo"));
Source

pub unsafe fn get_unchecked<I: SliceIndex<Self>>(&self, i: I) -> &I::Output

Returns an unchecked subslice of str.

This is the unchecked alternative to indexing the str.

§Safety

Callers of this function are responsible that these preconditions are satisfied:

  • The starting index must not exceed the ending index;
  • Indexes must be within bounds of the original slice;
  • Indexes must lie on UTF-8 sequence boundaries.

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

§Examples
let v = "🗻∈🌏";
unsafe {
    assert_eq!(v.get_unchecked(0..4), "🗻");
    assert_eq!(v.get_unchecked(4..7), "∈");
    assert_eq!(v.get_unchecked(7..11), "🌏");
}
Source

pub unsafe fn get_unchecked_mut<I: SliceIndex<Self>>( &mut self, i: I, ) -> &mut I::Output

Returns a mutable, unchecked subslice of str.

This is the unchecked alternative to indexing the str.

§Safety

Callers of this function are responsible that these preconditions are satisfied:

  • The starting index must not exceed the ending index;
  • Indexes must be within bounds of the original slice;
  • Indexes must lie on UTF-8 sequence boundaries.

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

§Examples
let mut v = String32::from("🗻∈🌏");
unsafe {
    assert_eq!(*v.get_unchecked_mut(0..2), String32::from("🗻∈"));
}
Source

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

Divide one string slice 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 method.

§Panics

Panics if mid is past the end of the last code point of the string slice.

§Examples

Basic usage:

let s = String32::from("Per Martin-Löf");

let (first, last) = s.split_at(3);

assert_eq!(first.to_owned(), String32::from("Per"));
assert_eq!(last.to_owned(), String32::from(" Martin-Löf"));
Source

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

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 UTF-8 code point.

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 method.

§Panics

Panics if mid is not on a UTF-8 code point boundary, or if it is past the end of the last code point of the string slice.

§Examples

Basic usage:

let mut s = String32::from("Per Martin-Löf");
{
    let (first, last) = s.split_at_mut(3);
    first.make_ascii_uppercase();
    assert_eq!(first.to_owned(), String32::from("PER"));
    assert_eq!(last.to_owned(), String32::from(" Martin-Löf"));
}
assert_eq!(s, String32::from("PER Martin-Löf"));
Source

pub fn make_ascii_uppercase(&mut self)

Converts this string to its ASCII upper case equivalent in-place.

ASCII letters ‘a’ to ‘z’ are mapped to ‘A’ to ‘Z’, but non-ASCII letters are unchanged.

To return a new uppercased value without modifying the existing one, use to_ascii_uppercase().

§Examples
let mut s = String32::from("Grüße, Jürgen ❤");

s.make_ascii_uppercase();

assert_eq!(s, String32::from("GRüßE, JüRGEN ❤"));
Source

pub fn make_ascii_lowercase(&mut self)

Converts this string to its ASCII lower case equivalent in-place.

ASCII letters ‘A’ to ‘Z’ are mapped to ‘a’ to ‘z’, but non-ASCII letters are unchanged.

To return a new lowercased value without modifying the existing one, use to_ascii_lowercase().

§Examples
let mut s = String32::from("GRÜßE, JÜRGEN ❤");

s.make_ascii_lowercase();

assert_eq!(s, String32::from("grÜße, jÜrgen ❤"));

Trait Implementations§

Source§

impl Debug for str32

Source§

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

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

impl Display for str32

Source§

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

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

impl From<&mut str> for &mut str32

Source§

fn from(s: &mut str) -> Self

Converts to this type from the input type.
Source§

impl From<&str> for &str32

Source§

fn from(s: &str) -> Self

Converts to this type from the input type.
Source§

impl<I> Index<I> for str32
where I: SliceIndex<str32>,

Source§

type Output = <I as SliceIndex<StringBase<[char]>>>::Output

The returned type after indexing.
Source§

fn index(&self, index: I) -> &I::Output

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

impl<I> IndexMut<I> for str32
where I: SliceIndex<str32>,

Source§

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

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

impl<T: ?Sized + AsRef<[char]>> PartialEq<T> for str32

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.