Hi there!
This book eventually became https://doc.rust-lang.org/stable/book/, please go read that instead!
Learn Rust
Home Page: http://rustforrubyists.com/
License: GNU Affero General Public License v3.0
Hi there!
This book eventually became https://doc.rust-lang.org/stable/book/, please go read that instead!
says i still work at balanced.
@steveklabnik , I like your rust_for_rubyists very much, can you add a lifetime section about rust? becouse i very confuse on it. thank you.
using the january 14 nightly, I am getting error: unresolved name
spawn
. Did you mean host
?
Chapter 6 still refers to spawn
often.
It looks like the tutorial content is made out of two nested HTML pages: one generated by pandoc and one from a template.
I'm not a pandoc expert but it seems like the --s (standalone) flag should be dropped from the Makefile.
http://johnmacfarlane.net/pandoc/README.html#templates
Also, I suggest to use --to=html5 to generate HTML5 instead of HTML4.01.
I was taking a look at the testing portion and when I tried to peek in to the binaries I got a some errors. Seems like OSX's version of nm
doesn't support the -C
flag. If you pipe the output of nm
into c++filt
though, i'll do the demangling and display everything nicely.
V8 has a lil script that acts as a wrapper http://v8.googlecode.com/svn/trunk/tools/mac-nm
Thoughts?
"fn spawn(f: proc())
But there’s that ~ again. This means that the pointer is an ‘owned pointer.’ We’ll talk more about what exactly that means in the next chapter, but you can infer from the name that this means that we own all of the references to the data in this closure."
The signature of spawn is no longer takes an owned pointer to a function, but a proc.
Running the Guessing Game program at the end of Chapter 11, it does not seem to recognise when I enter a number, instead always producing options of type none, I fixed this by changing
let num = from_str::<int>(input.slice_to(input.len() - 1));
to
let num = from_str::<int>(input.slice_to(input.len() - 2));
because I suspected that this method was trying to remove the \n
from the end of the input string, and \n
would be two characters.
Sorry, new to github so I believed this would be the best place to post about this, can this problem be confirmed?
$ rustc -v
rustc 0.10-pre (2ff358c 2014-01-17 15:46:40 -0800)
host: x86_64-unknown-linux-gnu
$ cat hello.rs
fn main() {
println("Hello, world.");
}
$ rustc hello.rs
hello.rs:2:5: 2:12 error: unresolved name `println`.
hello.rs:2 println("Hello, world.");
^~~~~~~
error: aborting due to previous error
task 'rustc' failed at 'explicit failure', /build/rust-git/src/rust/src/libsyntax/diagnostic.rs:75
task '<main>' failed at 'explicit failure', /build/rust-git/src/rust/src/librustc/lib.rs:448
I am able to fix this by adding
use std::io::println;
at the top, or by changing "println" to "println!"
Not sure how this should be fixed because I'm not sure what's going on :-/
In Chapter 5, the second time you're running nm
, you're calling it with nm -C fizzbuzz~
-- what's up with the tilde in the filename?
I don't see anything special you've done with rustc
when you're compiling without the test flag, and I don't see the tilde explained anywhere in the paragraph following... so I'm assuming this was like, copypasta or you're not showing a rename you did or something. But it's confusing.
Earlier tonight I installed mactex on Mac OS X 10.11 and got the book compiled, but it took a number of steps that I didn't immediately foresee. Because the default location of installations has changed in 10.11, you have to manually tell pandoc where the pdflatex engine is now.
So here are the commands that it took for me to get it working properly.
$ brew install pandoc
$ brew install homebrew/binary/kindlegen
if you need it
$ brew install Caskroom/cask/mactex
this will take awhile
and adding the latex-engine to a modified makefile made it work.
I'll be honest, I may have missed one install, but for the most part this should help speed it up.
rust-for-rubyists.epub: $(ALL_FILES)
pandoc --latex-engine=/Library/TeX/Root/bin/x86_64-darwin/pdflatex $(EPUB_OPTS) -o $@ $(CONTENTS)
rust-for-rubyists.pdf: $(ALL_FILES)
pandoc --latex-engine=/Library/TeX/Root/bin/x86_64-darwin/pdflatex $(EPUB_OPTS) -o $@ $(CONTENTS)
rust-for-rubyists.mobi: rust-for-rubyists.epub
kindlegen rust-for-rubyists.epub
book/book.html: $(CHAPTERS)
pandoc --latex-engine=/Library/TeX/Root/bin/x86_64-darwin/pdflatex -o $@ $(HTML_OPTS) $(CHAPTERS)
book/%.html : book/%.md
pandoc --latex-engine=/Library/TeX/Root/bin/x86_64-darwin/pdflatex -o $@ $(HTML_OPTS) $<
Here is a gist with the changes:
https://gist.github.com/skunkworker/1e215a9a28d235d35086
There have been a number of changes in the recent Rust update that causes the current code to not compile.
Some significant ones relevant to this book:
int
, and floating pointf64
. Literals must be suffixed with anThe entire list of changes is here: https://mail.mozilla.org/pipermail/rust-dev/2014-July/010655.html
hello.rs has this in it:
fn main() {
println!("Hello, world.");
}
When I try to compile:
$ rustc hello.rs
hello.rs:1:1: 1:1 error: can't find crate for `std`
hello.rs:1 fn main() {
^
error: aborting due to previous error
Version of Rust is:
$ rustc -v
rustc 0.11.0-nightly (a3257804df2bace236f83d9e5a9e887a1df30ef5 2014-07-08 00:31:42 +0000)
Not sure if this is a bug in nightly or in the code.
How I can help to maintaining the deployed version updated?
Just purchase the PDF today, but it doesn't match the repo, page 4 still shows
fn main() {
do 10.times {
do spawn {
let greeting_message = "Hello?"; println(greeting_message);
}
}
}
This ok().epxect() business we'll talk about in a minute. First, what's up with this use shenanigans? We've been using them forever, let's talk details.
expect
is misspelled.use
yet after the version updates.match input_num {
After "Awesome! We pass!"
Should we be doing use std::io::println;
instead of just using the standard println!
?
The rust tool is gone. I thought I had gotten rid of all of it but apparently not, chapter 5 at least still has references.
Thanks @bstrie.
In chapter 7, I was playing around with the code and wondered what would happen if I didn't deref the pointer in the code sample, so I changed it to:
let x: @int = @10;
println(x.to_str());
and was surprised to see the same 10
output. Digging into the language docs, I see that the dot operator automatically dereferences pointers. Is that worth mentioning in this chapter?
I took a look into chapter 11 and the code in the book
folder does not match the code in the code
folder.
I would like to equalise them (and also in other chapters as well). Is it safe to assume that the latest one should survive?
Hi @steveklabnik !
Thank you for full day of Rust last week! I was just going through your http://www.rustforrubyists.com/ (although I never did Ruby myself :D ) and got confused on the tasks chapter, precisely when you say:
This is really only one-way transit, though: what if we want to communicate back and forth? Setting up two ports and channels each time would be pretty annoying, so we have some standard library code for this.
And solve the problem by creating two pipes
again:
let (fromParentSender, fromParentReceiver) = channel();
let (fromChildSender, fromChildReceiver) = channel();
What's is the gain by using the std::comm::{channel, Sender, Receiver};
, seems like a the same let (chan, port) = channel();
Thank you!
obsolete syntax: `~` notation for owned pointers
now that the guide is real, this doesn't really matter anymore.
You mention that "The fundamental unit of computation in Rust is called a ‘task.’ Tasks are like threads, but you can choose the low-level details of how they operate." So that says to me that tasks are a Rust-specific term that doesn't exist in other language's terminology, but it's sorta like when other languages say threads but not quite.
What about pipe, channel, and port? Do other languages have these concepts and are they named the same thing? I know unix pipe, and I know server ports, those seem different... I don't really care exactly what the differences are at this point, just whether these terms would refer to the same concept in other languages' terminologies or not.
Code: NoSuchBucket
Message: The specified bucket does not exist
BucketName: www.rustforrubyists.com
RequestId: CFD57D2860DDB9A4
HostId: Gn/fbTcjOHRln14gCDy4EbBUIxlUcMs5Z4F1WX8E2XDZ0zIGHp+lPtIdtHnzTqtFIH+yFASfYxw=
Just working through the book (thanks), chapter 4 should be panic! now I think
http://stackoverflow.com/questions/26965066/rust-error-macro-undefined-fail
After "Because the if returns a value, we could also do something like this:" the println
should be println!
with appropriate arguments.
Reading through and trying out the examples for chapter 9 on vectors. The first example does not seem to be valid, at least with rust 0.11.
$ rustc --version
rustc 0.11.0-pre-nightly (7580ef9 2014-06-08 00:46:57 -0700)
host: x86_64-unknown-linux-gnu
$ cat vectors.rs
fn main() {
let your_favorite_numbers = ~[1i, 2, 3];
let my_favorite_numbers = ~[4i , 5, 6];
let our_favorite_numbers = your_favorite_numbers + my_favorite_numbers;
println!("The third favorite number is {:d}", our_favorite_numbers[2]);
}
$ rustc vectors.rs
vectors.rs:4:32: 4:75 error: binary operation `+` cannot be applied to type `~[int]`
vectors.rs:4 let our_favorite_numbers = your_favorite_numbers + my_favorite_numbers;
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
vectors.rs:6:51: 6:74 error: cannot determine a type for this bounded type parameter: unconstrained type
vectors.rs:6 println!("The third favorite number is {:d}", our_favorite_numbers[2]);
^~~~~~~~~~~~~~~~~~~~~~~
note: in expansion of format_args!
<std macros>:2:23: 2:77 note: expansion site
<std macros>:1:1: 3:2 note: in expansion of println!
vectors.rs:6:5: 6:76 note: expansion site
I'm honestly having some real trouble figuring out if there is a nice way to create a new vector c
that is the b
appended to a
looking through the rust documentation. Here's what I was able to come up with, but it seems to stray pretty far from the original example.
fn main() {
let my_favorite_numbers = vec!(1i, 2, 3);
let your_favorite_numbers = vec!(4i, 5, 6);
let our_favorite_numbers = my_favorite_numbers + your_favorite_numbers;
println!("The third favorite number is {:d}.", *our_favorite_numbers.get(2));
}
In the PDF version, any line of code longer than about 92 chars just gets cut off:
Online, at about 95 chars, the line gets wrapped, sometimes in the middle of words:
Same deal in the .mobi version in the amazon kindle for mac app:
The epub in iBooks on OSX seems to wrap ok.
I don't know whether you'd want to try making these lines shorter or making the different formats wrap correctly or if that's even possible :-/ Computers 😭
I was kind of confused about the tilde explanations/glossing over, but since tilde is going away, this can be fixed by taking those sections out :)
fn div_by_three(num: int) -> bool { false
}
Was giving me this error
error[E0412]: cannot find type `int` in this scope
--> src/main.rs:1:22
|
1 | fn div_by_three(num: int) -> bool {
| ^^^ not found in this scope
error: aborting due to previous error
For more information about this error, try `rustc --explain E0412`.
error: Could not compile `rusthelloworld`.
I had to switch it from int
to i64
to get example working
➜ rustc --version
rustc 1.38.0 (625451e37 2019-09-23)
Figured easier to open an issue than try to correct the example code with a PR since I am learning, and do not know, Rust.
This happens in print_vec_str
.
I know the book is for version 0.11 so feel free to close if this seems unnecessary, but making a note about this change could be useful.
I don't get the doubled up output as expected. Presumably this was fixed in newer Rust. Around "That’s it! We spin up 500 tasks that print stuff. If you inspect your output, you can tell it’s working:"
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.