Loading tutorials
&str is a borrowed view of text. String is an owned, growable buffer of text. This chapter explains how they differ and when to use each. Later chapters cover UTF-8, slicing, and the other string types in detail.2 min readOption and Result work. It explains what a str or String stores in memory. That model explains the byte-boundary rules you will meet when slicing and indexing in later chapters.2 min readprintln! works, and the difference between &str and String from the first chapter.2 min readOption and Result work. It covers the main ways to build an owned String, and how to choose among them.2 min read&str and String from earlier chapters. Only String can be edited in place. A &str is a read-only view, so every method below belongs to String and needs a mut binding.2 min readString differs from &str. You will learn three ways to combine text, and when each one fits.2 min readOption. It builds on the earlier chapters about &str, String, and UTF-8.2 min readOption and Result work. It also assumes you have read the earlier chapters on UTF-8 and slicing. A Rust string is a sequence of UTF-8 bytes, so "one character" can mean three different things. Rust gives you a sepa2 min readString differs from &str. You will learn which string type to put in a function signature and why callers rarely need to convert anything.2 min readOption and Result, and that a Rust str is UTF-8 text addressed by byte offsets. The methods below are defined on str, so they work on &str, &String, and literals. Most of them return slices that borrow from the original text and allo2 min readOption and Result, and how to slice a &str. You have already seen how to search and split text. Now you turn the pieces into typed values.2 min read&str and String, that both always hold valid UTF-8, and how Result and match work.2 min readOption and Result, and have used String with push and push_str. It covers how a String manages its memory and how to avoid reallocating it when you build text.2 min read&str and String, and how Option and Result work. Here you will learn how Cow<str> lets a function return borrowed text when it changed nothing, and owned text only when it did.2 min read&str and String, and that Rust strings are always valid UTF-8. It also assumes you are comfortable with Option and Result. Some text does not fit that guarantee, so the standard library has extra string types for it.2 min read