Type Definition generic_str::str32 [−][src]
pub type str32 = StringSlice<char>;
Expand description
Exactly the same as std::str
, except generic
Implementations
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());
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();
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.
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.
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.
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());
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"));
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), "🌏");
}
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("🗻∈"));
}
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"));
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"));
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 ❤"));
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 ❤"));