rokdocs
v0.1

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 CharsIter
Trait implementations 1
  • impl Iterator for CharsIter

SplitIter

pub struct SplitIter
Trait implementations 1
  • impl Iterator for SplitIter

LinesIter

pub struct LinesIter
Trait implementations 1
  • impl Iterator for LinesIter

CharIndicesIter

pub struct CharIndicesIter
Trait implementations 1
  • impl Iterator for CharIndicesIter

SplitWhitespaceIter

pub struct SplitWhitespaceIter
Trait implementations 1
  • impl Iterator for SplitWhitespaceIter

StrBuf

pub struct StrBuf

A 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() -> StrBuf
  • pub const fn with_capacity(cap: usize) -> StrBuf
  • pub const fn len(self) -> usize

    Byte length.

  • pub const fn is_empty(self) -> bool
  • pub const fn capacity(self) -> usize
  • pub const fn clear(self)
  • pub const fn reserve(self, additional: usize)

    Room for additional more 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_str hands out the bytes as a str, which must be UTF-8 (2.15.1); the caller keeps them so by the time it is called. Bytes of unknown encoding go through str::from_utf8.

  • pub const fn to_str(self) -> str

    The current contents as an immutable str (a copy).

Trait implementations 4
  • impl !Sync for StrBuf
  • impl Sliceable<Range<usize>> for StrBuf
  • impl Display for StrBuf
  • impl Transfer for StrBuf

Utf8Error

pub struct Utf8Error

Bytes that are not UTF-8 (str::from_utf8).

  • pub valid_up_to: usize
Trait implementations 3
  • impl Display for Utf8Error
  • impl Debug for Utf8Error
  • impl Error for Utf8Error

Traits

FromStr

pub trait FromStr

str.parse::<T>() dispatch.

  • type Err
  • fn 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() -> str
  • pub const fn from_utf8(bytes: List<u8> | Slice<u8>) throws (Utf8Error) -> str

    bytes as a str; throws if they are not UTF-8 (2.15.6).

  • pub const fn from_utf8_lossy(bytes: List<u8> | Slice<u8>) -> str

    bytes as a str with 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 empty str gives 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) -> u8

    Byte i, O(1); panics if i >= len().

  • pub const fn len(self) -> usize

    Byte length (not the char count).

  • pub const fn is_empty(self) -> bool
  • pub const fn char_count(self) -> usize

    Number of chars (s.chars().count() in the spec).

  • pub const fn contains(self, pat: str) -> bool
  • pub const fn starts_with(self, pat: str) -> bool
  • pub const fn ends_with(self, pat: str) -> bool
  • pub const fn find(self, pat: str) -> usize | none
  • pub const fn rfind(self, pat: str) -> usize | none
  • pub const fn strip_prefix(self, prefix: str) -> str | none

    self without a leading prefix, or none if it does not start with it.

  • pub const fn strip_suffix(self, suffix: str) -> str | none

    self without a trailing suffix, or none.

  • pub const fn split_once(self, sep: str) -> (str, str) | none

    The pieces before and after the first sep, or none.

  • pub const fn repeat(self, n: usize) -> str

    n copies back to back.

  • pub const fn trim(self) -> str
  • pub const fn trim_start(self) -> str
  • pub const fn trim_end(self) -> str
  • pub const fn to_lowercase(self) -> str

    Full Unicode case mapping ("ß" → "SS", final σ → ς); no locale rules.

  • pub const fn to_uppercase(self) -> str
  • pub const fn replace(self, from: str, to: str) -> str
  • pub const fn chars(self) -> CharsIter

    Unicode scalar values, in order.

  • pub fn bytes(self) -> BytesIter

    UTF-8 bytes, in order.

  • pub const fn split(self, sep: str) -> SplitIter

    The pieces between occurrences of sep (all of them, empty ones included).

  • pub const fn lines(self) -> LinesIter

    Lines 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) -> SplitWhitespaceIter

    The non-empty pieces between runs of Unicode White_Space (the set trim strips).

  • pub const fn parse<T: FromStr>(self) throws (T::Err) -> T

    T's value spelled by this string (stdlib 2.15.7).

Trait implementations 10
  • impl Sliceable<Range<usize>> for str
  • impl Add for str
  • impl PartialEq for str
  • impl PartialOrd for str
  • impl Eq for str
  • impl Ord for str
  • impl Hash for str
  • impl FromIterator<char> for str
  • impl FromIterator<str> for str
  • impl FromStr for str

impl char

  • pub const fn from_u32(n: u32) -> char | none

    n as a char; none for a surrogate or a value past U+10FFFF. (as char takes only a u8.)

  • pub const unsafe fn from_u32_unchecked(n: u32) -> char

    n as a char, unchecked: n must be a Unicode scalar value.

  • pub const fn from_digit(d: u32, radix: u32) -> char

    Digit d in base radix (2..=36; lowercase letters past 9). Panics if d is not a digit of that base.

  • pub const fn to_digit(self, radix: u32) throws (ValueError) -> u32

    The 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) -> bool
  • pub const fn len_utf8(self) -> usize

    Bytes in UTF-8.

  • pub const fn len_utf16(self) -> usize

    16-bit units in UTF-16.

  • pub const fn is_alphabetic(self) -> bool
  • pub const fn is_lowercase(self) -> bool
  • pub const fn is_uppercase(self) -> bool
  • pub const fn is_whitespace(self) -> bool

    Unicode White_Space.

  • pub const fn is_numeric(self) -> bool

    General category Nd, Nl or No.

  • pub const fn is_alphanumeric(self) -> bool
  • pub const fn is_control(self) -> bool

    General category Cc.

  • pub const fn to_lowercase(self) -> char

    The simple (one-char) lowercase mapping; self if none. Strings map fully with str::to_lowercase.

  • pub const fn to_uppercase(self) -> char

    The simple (one-char) uppercase mapping ('ß' stays 'ß'; "ß" becomes "SS" through str::to_uppercase).

  • pub const fn is_ascii(self) -> bool
  • pub const fn is_ascii_uppercase(self) -> bool
  • pub const fn is_ascii_lowercase(self) -> bool
  • pub const fn is_ascii_alphabetic(self) -> bool
  • pub const fn is_ascii_digit(self) -> bool
  • pub const fn is_ascii_alphanumeric(self) -> bool
  • pub const fn is_ascii_hexdigit(self) -> bool
  • pub const fn is_ascii_whitespace(self) -> bool

    Space, \t, \n, form feed, \r.

  • pub const fn is_ascii_control(self) -> bool
  • pub const fn is_ascii_graphic(self) -> bool

    ! ..= ~ (printable, not space).

  • pub const fn is_ascii_punctuation(self) -> bool
  • pub const fn to_ascii_uppercase(self) -> char
  • pub const fn to_ascii_lowercase(self) -> char
  • pub const fn eq_ignore_ascii_case(self, other: char) -> bool
Trait implementations 4
  • impl PartialOrd for char
  • impl Ord for char
  • impl TryFrom<u32> for char
  • impl FromStr for char