rstd 0.1.0
Loading...
Searching...
No Matches
alloc::string::String Class Referenceexport
module rstd.alloc

A UTF-8 encoded, growable string, analogous to Rust's String. More...

Public Member Functions

auto as_ref () const noexcept -> ref< ffi::CStr >
 Returns a reference to the string as a CStr.
 
constexpr operator ref< str > () const
 Converts the String to a ref<str> string slice.
 
void push_back (char c)
 Appends a char to the end of this string.
 
void push_back (u8 c)
 Appends a byte to the end of this string.
 
void push (char32_t cp)
 Appends a Unicode code point, encoding as UTF-8.
 
constexpr auto as_str () const noexcept -> ref< str >
 Returns a string slice of the entire String.
 
constexpr auto len () const noexcept -> usize
 Returns the byte length of this string.
 
constexpr auto is_empty () const noexcept -> bool
 Returns true if this string contains no bytes.
 
constexpr auto capacity () const noexcept -> usize
 Returns the current capacity in bytes.
 
constexpr void clear ()
 Clears the string, removing all bytes.
 
void truncate (usize new_len)
 Truncates the string to new_len bytes.
 
constexpr auto as_raw_ptr () const noexcept -> const u8 *
 Returns a raw pointer to the underlying byte buffer.
 
constexpr auto begin () const noexcept -> const char *
 Returns a const iterator to the beginning of the string.
 
constexpr auto end () const noexcept -> const char *
 Returns a const iterator to the end of the string.
 
constexpr auto data () const noexcept -> const char *
 Returns a pointer to the string data as a char array.
 
constexpr auto size () const noexcept -> usize
 Returns the length of the string in bytes.
 

Static Public Member Functions

static auto make () -> String
 Creates a new empty String.
 
static auto make (ref< str > s) -> String
 Creates a String from a string slice (copies the bytes).
 
static auto make (const char *s) -> String
 Creates a String from a null-terminated C string (copies the bytes).
 
static auto from_utf8_unchecked (Vec< u8 > &&bytes) -> String
 Creates a new String from a byte vector without checking UTF-8 validity.
 

Detailed Description

A UTF-8 encoded, growable string, analogous to Rust's String.

Member Function Documentation

◆ as_raw_ptr()

auto alloc::string::String::as_raw_ptr ( ) const -> const u8*
inlineconstexprnoexcept

Returns a raw pointer to the underlying byte buffer.

Returns
A const pointer to the first byte.

◆ as_ref()

auto alloc::string::String::as_ref ( ) const -> ref<ffi::CStr>
inlinenoexcept

Returns a reference to the string as a CStr.

Returns
A ref<CStr> view of the string data.

◆ data()

auto alloc::string::String::data ( ) const -> const char*
inlineconstexprnoexcept

Returns a pointer to the string data as a char array.

Returns
A const char* pointer to the data.

◆ size()

auto alloc::string::String::size ( ) const -> usize
inlineconstexprnoexcept

Returns the length of the string in bytes.

Returns
The number of bytes in the string.

◆ truncate()

void alloc::string::String::truncate ( usize new_len)
inline

Truncates the string to new_len bytes.

Panics if new_len is not on a UTF-8 character boundary.


The documentation for this class was generated from the following file: