For a list of documents, see: Rust Mobile Complex Graphics Rendering Project Development Series summary (table of Contents)

The mapping between the data types and Rust when C++ is compiled for 64-bit systems is shown below.

C++ Rust
void std::os::raw::c_void
char i8
short i16
int i32
long i64
unsigned char u8
unsigned short u16
unsigned int u32
unsigned long u64
size_t usize
float f32
double f64
bool bool
char* &str
std::string String

Char (i8, u8); char (i8, u8); char (u8);

Iterates over each character of a String

for c in my_str.chars() { 
    // do something with `c`
}

for (i, c) in my_str.chars().enumerate() {
    // do something with character `c` and index `i`
}
Copy the code

LeetCode exercises:

  • 771. Jewels and Stones

Reference:

  • How do you iterate over a string by character
  • How to index a String in Rust