Working with strings in Rust
There's a question that always comes up when people pick up the Rust programming language: why are there two string types? Why is there String, and &str? My Declarative Memory Management article answers the question partially, but there is a lot more to say about it, so let's run a few experiments and see if we can conjure up a thorough defense of Rust's approach over, say, C's. Let's start with a simple C program that prints its arguments. Okay! Simple enough. We're using the standard C11 main function signature, which takes the number of argument (argc, for argument count) as an int, and an "array" of "strings" (argv, for argument vector) as a char**, or char *[]. Then we use the printf format specifier %s to print each argument as a string - followed by \n, a newline. And sure enough, it prints each argument on its own line. Before proceeding, let's make sure we have a proper understanding of what's going on. Now we're using the %p format specifier, which prints.. pointers! Okay, so
Working with strings in Rust Working with strings in Rust Feb 19, 2020 45 min #rust Thanks to my sponsors: Steven Pham, budrick, Thehbadger, Xirvik Servers, Mathias Brossard, Olivier Peyrusse, Lucille Blumire, Antoine Rouaze, Ronen Cohen, Romain Ruetschi, Reto Trappitsch, Blake Johnson, Ross Williams, Yuriy Taraday, Tom Forbes, Brian L. Troutwine, Michal Hošna, Max von Forell, Timothée Gerber, Max Bruckner and 241 more Steven Pham, budrick, Thehbadger, Xirvik Servers, Mathias Brossard, Olivier Peyrusse, Lucille Blumire, Antoine Rouaze, Ronen Cohen, Romain Ruetschi, Reto Trappitsch, Blake Johns
Explore this link on the map →saved by
related reading
- Storing UTF-8 Encoded Text with Strings - The Rust Programming Languagedoc.rust-lang.org
- A half-hour to learn Rustfasterthanli.me
- The Slice Type - The Rust Programming Languagedoc.rust-lang.org
- Rust Language Cheat Sheetcheats.rs
- What is Ownership? - The Rust Programming Languagedoc.rust-lang.org
- References and Borrowing - The Rust Programming Languagedoc.rust-lang.org
- Rewriting Bun in Rust | Bun Blogbun.com
- Programming a Guessing Game - The Rust Programming Languagedoc.rust-lang.org
- What makes Rust special - Rust for C-Programmersrust-for-c-programmers.com
- (Re)writing an interpreter in Rust – Danny van Kootendannyvankooten.com
- Data Types - The Rust Programming Languagedoc.rust-lang.org
- Defining an Enum - The Rust Programming Languagedoc.rust-lang.org