rok::core::str
rok::core::str - str methods and trait impls (stdlib 2.15).
str is an immutable (ptr, len) value (2.15.1): literals are static
bytes, run-time strings GC objects, and a slice shares its source's
bytes, so slicing, lines, split*, trim* and strip_* copy
nothing. StrBuf is the growable buffer.
Structs
CharsIter
pub struct CharsIterTrait implementations 1
impl Iterator for CharsIter
SplitIter
pub struct SplitIterTrait implementations 1
impl Iterator for SplitIter
LinesIter
pub struct LinesIterTrait implementations 1
impl Iterator for LinesIter
CharIndicesIter
pub struct CharIndicesIterTrait implementations 1
impl Iterator for CharIndicesIter
SplitWhitespaceIter
pub struct SplitWhitespaceIterTrait implementations 1
impl Iterator for SplitWhitespaceIter
StrBuf
pub struct StrBufA growable UTF-8 buffer. A handle like the collections: copies share the buffer, one object holding the length, the capacity and the bytes.
pub const fn new() -> StrBufpub const fn with_capacity(cap: usize) -> StrBufpub const fn len(self) -> usizeByte length.
pub const fn is_empty(self) -> boolpub const fn capacity(self) -> usizepub const fn clear(self)pub const fn reserve(self, additional: usize)Room for
additionalmore bytes (doubling).pub const fn push(self, c: char)Append
c, UTF-8 encoded.pub const fn push_str(self, s: str)pub const unsafe fn push_byte(self, b: u8)Append one byte.
unsafe:to_strhands out the bytes as astr, which must be UTF-8 (2.15.1); the caller keeps them so by the time it is called. Bytes of unknown encoding go throughstr::from_utf8.pub const fn to_str(self) -> strThe current contents as an immutable
str(a copy).
Trait implementations 4
impl !Sync for StrBufimpl Sliceable<Range<usize>> for StrBufimpl Display for StrBufimpl Transfer for StrBuf
Utf8Error
pub struct Utf8ErrorBytes that are not UTF-8 (str::from_utf8).
pub valid_up_to: usize
Trait implementations 3
impl Display for Utf8Errorimpl Debug for Utf8Errorimpl Error for Utf8Error
Traits
FromStr
pub trait FromStrstr.parse::<T>() dispatch.
type Errfn from_str(s: str) throws (Err) -> Self
Type aliases
BytesIter
pub type BytesIter = SliceIter<u8>What s.bytes() returns (2.15.1): the bytes of the as_bytes view.
Implementations
impl str
pub const fn new() -> strpub const fn from_utf8(bytes: List<u8> | Slice<u8>) throws (Utf8Error) -> strbytesas astr; throws if they are not UTF-8 (2.15.6).pub const fn from_utf8_lossy(bytes: List<u8> | Slice<u8>) -> strbytesas astrwith each ill-formed run replaced by U+FFFD, one per maximal subpart (Unicode 3.9 "U+FFFD Substitution of Maximal Subparts", as WHATWG UTF-8 decode does).pub fn as_bytes(self) -> Slice<u8>The UTF-8 bytes as a read-only view of the string itself (no copy, O(1)).
pub fn as_ptr(self) -> rok::bare::ptr::ConstPtr<u8>The first byte's address, for FFI (
len()bytes, no NUL promised; an emptystrgives a dangling pointer). Valid while a variable holding the string is in scope in a function where a pointer type appears (2.15.2); pin it to keep it longer.pub const fn byte(self, i: usize) -> u8Byte
i, O(1); panics ifi >= len().pub const fn len(self) -> usizeByte length (not the char count).
pub const fn is_empty(self) -> boolpub const fn char_count(self) -> usizeNumber of chars (
s.chars().count()in the spec).pub const fn contains(self, pat: str) -> boolpub const fn starts_with(self, pat: str) -> boolpub const fn ends_with(self, pat: str) -> boolpub const fn find(self, pat: str) -> usize | nonepub const fn rfind(self, pat: str) -> usize | nonepub const fn strip_prefix(self, prefix: str) -> str | noneselfwithout a leadingprefix, ornoneif it does not start with it.pub const fn strip_suffix(self, suffix: str) -> str | noneselfwithout a trailingsuffix, ornone.pub const fn split_once(self, sep: str) -> (str, str) | noneThe pieces before and after the first
sep, ornone.pub const fn repeat(self, n: usize) -> strncopies back to back.pub const fn trim(self) -> strpub const fn trim_start(self) -> strpub const fn trim_end(self) -> strpub const fn to_lowercase(self) -> strFull Unicode case mapping (
"ß"→"SS", finalσ→ς); no locale rules.pub const fn to_uppercase(self) -> strpub const fn replace(self, from: str, to: str) -> strpub const fn chars(self) -> CharsIterUnicode scalar values, in order.
pub fn bytes(self) -> BytesIterUTF-8 bytes, in order.
pub const fn split(self, sep: str) -> SplitIterThe pieces between occurrences of
sep(all of them, empty ones included).pub const fn lines(self) -> LinesIterLines without their
\n/\r\n; a final line ending adds no empty line.pub const fn char_indices(self) -> CharIndicesIter(byte offset, char)pairs.pub const fn split_whitespace(self) -> SplitWhitespaceIterThe non-empty pieces between runs of Unicode
White_Space(the settrimstrips).pub const fn parse<T: FromStr>(self) throws (T::Err) -> TT's value spelled by this string (stdlib 2.15.7).
Trait implementations 10
impl Sliceable<Range<usize>> for strimpl Add for strimpl PartialEq for strimpl PartialOrd for strimpl Eq for strimpl Ord for strimpl Hash for strimpl FromIterator<char> for strimpl FromIterator<str> for strimpl FromStr for str
impl char
pub const fn from_u32(n: u32) -> char | nonenas a char;nonefor a surrogate or a value past U+10FFFF. (as chartakes only au8.)pub const unsafe fn from_u32_unchecked(n: u32) -> charnas a char, unchecked:nmust be a Unicode scalar value.pub const fn from_digit(d: u32, radix: u32) -> charDigit
din baseradix(2..=36; lowercase letters past9). Panics ifdis not a digit of that base.pub const fn to_digit(self, radix: u32) throws (ValueError) -> u32The value of this digit in base
radix(2..=36, either letter case); throws if it is not one.pub const fn is_digit(self, radix: u32) -> boolpub const fn len_utf8(self) -> usizeBytes in UTF-8.
pub const fn len_utf16(self) -> usize16-bit units in UTF-16.
pub const fn is_alphabetic(self) -> boolpub const fn is_lowercase(self) -> boolpub const fn is_uppercase(self) -> boolpub const fn is_whitespace(self) -> boolUnicode
White_Space.pub const fn is_numeric(self) -> boolGeneral category
Nd,NlorNo.pub const fn is_alphanumeric(self) -> boolpub const fn is_control(self) -> boolGeneral category
Cc.pub const fn to_lowercase(self) -> charThe simple (one-char) lowercase mapping;
selfif none. Strings map fully withstr::to_lowercase.pub const fn to_uppercase(self) -> charThe simple (one-char) uppercase mapping (
'ß'stays'ß';"ß"becomes"SS"throughstr::to_uppercase).pub const fn is_ascii(self) -> boolpub const fn is_ascii_uppercase(self) -> boolpub const fn is_ascii_lowercase(self) -> boolpub const fn is_ascii_alphabetic(self) -> boolpub const fn is_ascii_digit(self) -> boolpub const fn is_ascii_alphanumeric(self) -> boolpub const fn is_ascii_hexdigit(self) -> boolpub const fn is_ascii_whitespace(self) -> boolSpace,
\t,\n, form feed,\r.pub const fn is_ascii_control(self) -> boolpub const fn is_ascii_graphic(self) -> bool!..=~(printable, not space).pub const fn is_ascii_punctuation(self) -> boolpub const fn to_ascii_uppercase(self) -> charpub const fn to_ascii_lowercase(self) -> charpub const fn eq_ignore_ascii_case(self, other: char) -> bool
Trait implementations 4
impl PartialOrd for charimpl Ord for charimpl TryFrom<u32> for charimpl FromStr for char