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
impl str32
Sourcepub fn is_empty(&self) -> bool
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());Sourcepub fn as_ptr(&self) -> *const char
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();Sourcepub fn as_mut_ptr(&mut self) -> *mut char
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.
Sourcepub fn from_slice(data: &[char]) -> &Self
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.
Sourcepub fn from_slice_mut(data: &mut [char]) -> &mut Self
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.
Sourcepub fn get<I: SliceIndex<Self>>(&self, i: I) -> Option<&I::Output>
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());Sourcepub fn get_mut<I: SliceIndex<Self>>(&mut self, i: I) -> Option<&mut I::Output>
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"));Sourcepub unsafe fn get_unchecked<I: SliceIndex<Self>>(&self, i: I) -> &I::Output
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), "🌏");
}Sourcepub unsafe fn get_unchecked_mut<I: SliceIndex<Self>>(
&mut self,
i: I,
) -> &mut I::Output
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("🗻∈"));
}Sourcepub fn split_at(&self, mid: usize) -> (&Self, &Self)
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"));Sourcepub fn split_at_mut(&mut self, mid: usize) -> (&mut Self, &mut Self)
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"));Sourcepub fn make_ascii_uppercase(&mut self)
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 ❤"));Sourcepub fn make_ascii_lowercase(&mut self)
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 ❤"));