More often than not, I think that an easy answer is default a locks to a pointer.
So I tend I know there's like 17 rules to why you should use a pointer and go and when you shouldn't use a pointer. As I just a good thing to remember I've been bit by this multiple times. Instead, a pointer receiver on the other hand will change that answer because you are manipulating the thing that is pointing to yours as opposed to a copy of what you had. This can just massively screw you up, so just be careful. So that is just something you should always keep in your head. So when I have f.thing equals five, your f does not get changed.
A value receiver does not do anything with the statement. I did mention this earlier, all right? So if you have a struct foo, and you have a thing, you can have what is referred to as a value receiver or a pointer receiver. All right, so I did wanna also go over some like, hey, here are some language gotchas that I think are important. And so we should see how these things really play out in practical rust as opposed to these simple operations which often you don't actually run into problems in the simple ones. And I've even pre-planned it as long as I don't screw it up and program it correctly like a massive ownership problem that should happen at the end. So as we program, our little CLI app, there will be times in which we are going to run into these. So okay, we ran into pretty much virtually no ownership problems because we're just passing values, all right? We wouldn't ever hold on to things. And so of course the whole goal of that last section was just to get us a little bit familiar with rust. But if you didn't know those methods exist or what they do, it's a really hard problem to solve. > I mean, I don't know, rust was pretty cool, all right? Once those methods exist, it's actually a fairly trivial problem to solve. To learn more, run the command again with -verbose.Transcript from the "Pointer, Struct & Error Gotchas" Lesson | ^^^^^^^^^^ method not found in `solution::Csv>`ġ50 | let row = csv.parse_line(r#"" Name With Spaces "," 13 ","0-0-0""#).unwrap() ġ62 | let row = csv.parse_line(r#""13", "Name, Basic""#).unwrap() ġ68 | let row = csv.parse_line(r#""13, or maybe 14","Basic Name""#).unwrap() Ģ18 | let filtered_names = csv.map(|row| row.unwrap().clone()).collect::>() Įrror: aborting due to 14 previous errorsįor more information about this error, try `rustc -explain E0599`.
| ^^^^^^^^^^^^^^^ method not found in `solution::Csv>`Ģ63 | csv.write_to(&mut output).unwrap() Ģ85 | csv.write_to(&mut output).unwrap() Įrror: no method named `parse_line` found for struct `solution::Csv>` in the current scopeġ44 | let row = csv.parse_line(r#""Basic Name","13","""#).unwrap() | ^^^^^^^^ method not found in `solution::Csv>`Įrror: no method named `apply_selection` found for struct `solution::Csv>` in the current scopeĢ60 | csv.apply_selection(|row| Ok(row.contains("."))) Which is required by `&mut solution::Csv>: Iterator`Įrror: no method named `write_to` found for struct `solution::Csv>` in the current scopeĢ34 | csv.write_to(&mut output).unwrap() = note: the method `map` exists but the following trait bounds were not satisfied: | - doesn't satisfy `solution::Csv>: Iterator` | ^^^ method not found in `solution::Csv>` | ^^^^ method not found in `solution::Csv>`Įrror: no method named `map` found for struct `solution::Csv>` in the current scopeġ95 | let filtered_names = csv.map(|row| row.unwrap().clone()).collect::>() = note: this `Result` may be an `Err` variant, which should be handledĮrror: no method named `next` found for struct `solution::Csv>` in the current scopeħ0 | let row = csv.next().unwrap().unwrap() Warning: unused `std::result::Result` that must be used | ^ help: convert the identifier to snake case (notice the capitalization): `o` Warning: variable `O` should have a snake case name Warning: field is never read: `selection` Warning: unused import: `std::io::BufReader`