I'm struggling quite a bit with this part. Here, as in previous examples, we're setting the variable reference_to_nothing = the result of a function called dangle().īut, when we move to the function, the result is &s. The string itself lives in the section of the heap that the pointer is pointing to. This pointer contains information regarding where to find the string, the size of the string, and the reserved space (since it is mutable and could be subject to change, we want reserved space to account for potential change). But s isn't the string itself, but rather a pointer. Here, because we're working with a string, s is stored on the stack. But why does the same principle not apply if fn_name is above chungus? Since piper was used with println!, does that mean that ownership of fn_name's return value has been freed? Meaning, ownership lasts until the value is used?īut why can we not call fn_name in the chungus function? If, for example, the fn_name function was above main, we could still call it from within main. When does something truly come out of scope? What I mean is the following: fn main() ", piper) line, add another variable that receives ownership of the return value of fn_name. We don't know what the user is going to type, and it could be a lot or very little. Immutable variables such as "let x = 5" will be stored on the stack because there is no opportunity during runtime for that variable to change.īut, a mutable variable, such as taking user input, is stored on the heap so that it can be growable. The stack is memory for known, fixed values that will not be changed. So, I'd like to get as much as help as I can in understanding exactly what's going on. Not hopelessly confused, but I feel like it's a bad idea to continue with a poor understanding of the basics. The documentation is great, the book is fantastic, and I feel like I'm learning a lot.īut, as I've heard with people learning about pointers for the first time, I'm definitely confused about the memory. And even with my first experiences with references, memory allocation, etc., I think it's still going pretty well. So, few days or weeks ago (I'm incapable of remembering how long something has took), I mentioned that I wanted to learn Rust as my first language. We'll do our best to keep these links up to date, but if we fall behind please don't hesitate to shoot us a modmail. This is not an official Rust forum, and cannot fulfill feature requests. Err on the side of giving others the benefit of the doubt.Īvoid re-treading topics that have been long-settled or utterly exhausted. Please create a read-only mirror and link that instead.Ī programming language is rarely worth getting worked up over.īe charitable in intent. If criticizing a project on GitHub, you may not link directly to the project's issue tracker. Post titles should include useful context.įor Rust questions, use the stickied Q&A thread.Īrts-and-crafts posts are permitted on weekends.Ĭriticism is encouraged, though it must be constructive, useful and actionable. For content that does not, use a text post to explain its relevance. Posts must reference Rust or relate to things using Rust. We observe the Rust Project Code of Conduct. Strive to treat others with respect, patience, kindness, and empathy. Please read The Rust Community Code of Conduct The Rust Programming LanguageĪ place for all things related to the Rust programming language-an open-source systems language that emphasizes performance, reliability, and productivity.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |