Loading tutorials
&str is a borrowed view of text that someone else owns. String is an owned, growable buffer. This chapter explains how each is laid out in memory, how to convert between them, and how to pick one in y5 min readstr or String. It assumes you know basic Rust syntax, ownership and borrowing, and Option and Result. It also assumes you know the difference between &str and String from the previous chapter. Here the focus is on bytes, code points, and the guaran6 min read&str and String as the borrowed and owned string types. It also assumes you can read a println! call. Later chapters cover creating and changing String values.6 min readOption and Result work. It also assumes you already know the difference between &str and String from the first chapter. Here the focus is on the many ways to produce an owned String, what each one costs, and 4 min readOption works. It also assumes you have read the earlier chapters on &str versus String and on UTF-8. You will learn how to add to, remove from, and rewrite a String in place. You will also learn which edits can5 min read&str and String, how ownership moves a value, and how to call methods that return Option or Result. It covers the main ways to combine text into a new String, what each way costs, and how to pick one.5 min readOption. It also assumes you have read the earlier chapter on UTF-8, where you saw that str is a sequence of bytes that must be valid UTF-8. Here you will use that fact to slice strings, and you will see why Rust refuse5 min read&str and String, that Rust strings are always valid UTF-8, and that slicing uses byte offsets. You also need basic familiarity with iterators such as for, map, and collect.5 min read&str and String from earlier chapters. It covers how to choose parameter types for text, and why &str accepts so many different arguments.5 min read&str and String, that you know strings are UTF-8 and slice by byte offset, and that you can work with Option and iterators.4 min readOption and Result work. It also assumes you have seen split_once and trim from the previous chapter on searching and splitting. Here you will turn text into numbers, booleans, and your own types, and handle the4 min readString and &str always hold valid UTF-8, that you can use Result and match, and that you have read the earlier chapters on creating strings and slicing on byte offsets. Here you will see where invalid bytes come from, how to detect them, and which recovery 5 min readString differs from &str. You should also have seen push, push_str, and format!. Here you will learn how a String manages its memory, when it allocates, and how to avoid allocations you do not need.6 min read&str and String, understand ownership and borrowing, and can work with Option and Result. It builds on the chapters about function signatures and about growing and changing a String.5 min read&str and String split from earlier chapters and that str is always valid UTF-8. It also assumes you are comfortable with Option, Result, and borrowing. Here you will learn why String is the wrong type for file names, environment variables, and C interop,6 min read