Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New post: Rust by trial and error #9

Merged
merged 2 commits into from Oct 17, 2015
Merged

New post: Rust by trial and error #9

merged 2 commits into from Oct 17, 2015

Conversation

@IanWhitney
Copy link
Owner

IanWhitney commented Oct 2, 2015

No description provided.


In Ruby a instance method automatically has access to `self`. [Rust methods don't](https://doc.rust-lang.org/stable/book/method-syntax.html). I'm fuzzy on this point, but here's what I think is going on. In the Ruby code `year.is_leap?`, `year` is the receiver of the `is_leap?` method call. Inside the method the receiver can be accessed by using `self` (or leaving `self` off entirely, in most cases).

But because of Rust's focus on proper memory management, we have to tell the method how it's going to use the receiver so that it can properly handl the memory. Is it a reference, a value or a mutable reference. I'll be honest. I don't quite understand what that means. And I might be totally wrong about all of it! But `&self` is the most common way of providing self, so that's what I'm doing.

This comment has been minimized.

Copy link
@steveklabnik
IanWhitney added a commit that referenced this pull request Oct 17, 2015
New post: Rust by trial and error
@IanWhitney IanWhitney merged commit af8f0a1 into master Oct 17, 2015
@IanWhitney IanWhitney deleted the rust branch Oct 17, 2015
@amaceing
Copy link

amaceing commented Apr 5, 2016

Hey man, I just read your Rust by its Core Values blog and really liked it. Taking a look at your other Rust articles and just finished this one as well. I've learned more about Rust in those two articles than the 3 times I've tried to read the documentation/book.Keep them coming!

With your Rust experience now, was the implementation of this test case a little overkill? Feels very Ruby.

@IanWhitney
Copy link
Owner Author

IanWhitney commented Apr 5, 2016

@amaceing Glad you liked them. My Rust code is definitely going to look Ruby-ish. For the purposes of passing the tests, this code is overkill. But as part of a 'real' code base, maybe not.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

3 participants
You can’t perform that action at this time.