GithubHelp home page GithubHelp logo

steveklabnik / rust_for_rubyists Goto Github PK

View Code? Open in Web Editor NEW
425.0 425.0 61.0 843 KB

Learn Rust

Home Page: http://rustforrubyists.com/

License: GNU Affero General Public License v3.0

Ruby 0.78% Rust 25.87% HTML 66.00% CSS 2.31% Makefile 5.05%

rust_for_rubyists's Introduction

rust_for_rubyists's People

Contributors

aag avatar aaroncm avatar adrientetar avatar bcj avatar bruceadams avatar carols10cents avatar cdwort avatar dskecse avatar emberian avatar ende76 avatar erpe avatar franklinchou avatar gregmalcolm avatar jbcrail avatar jefflembeck avatar jsanders avatar knowtheory avatar mehulkar avatar mttrs avatar o-i avatar posborne avatar robinst avatar steveklabnik avatar tcfuji avatar tdclark avatar timt51 avatar vrinek avatar wagenet avatar zamith avatar zedshaw avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

rust_for_rubyists's Issues

spawn is not a valid command

using the january 14 nightly, I am getting error: unresolved name spawn. Did you mean host?

Chapter 6 still refers to spawn often.

Text in chapter 6 explaining spawn is not correct

"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.

Guessing Game: Number input fails to produce Option int, instead produces Option none

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?

Hello world fails with "Unresolved name `println`"

$ 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!"

Ch 5: Why does `nm -C fizzbuzz~` have a tilde after the filename?

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.

Mac OS X 10.11 El Capitan makes LaTeX installation more difficult

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

Rust 0.11.0 changes

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:

  1. ~T has been removed from the language. This type is superseded by the
    Box type
  2. Integral literals no longer default to int, and floating point
    literals no longer default to f64. Literals must be suffixed with an
    appropriate type if inference cannot determine the type of the
    literal.

The entire list of changes is here: https://mail.mozilla.org/pipermail/rust-dev/2014-July/010655.html

Hello World throwing error - hello.rs:1:1: 1:1 error: can't find crate for `std`

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.

PDF Copy on purchase inconsistent with repo

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);
        }
    }
}

Ch 11: Minor issues

  • 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.
    • We haven't actually be using use yet after the version updates.
  • Bad indenting in match input_num {

`use println` in Ch 10

Should we be doing use std::io::println; instead of just using the standard println!?

Worth explaining auto-dereferencing?

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?

Code snippets in `book` and `code` folders do not match

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?

Q: standard channels vs use std::comm::{channel, Sender, Receiver};

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!

Are pipe, channel, and port the same or different as other langs?

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.

Website is down


    Code: NoSuchBucket
    Message: The specified bucket does not exist
    BucketName: www.rustforrubyists.com
    RequestId: CFD57D2860DDB9A4
    HostId: Gn/fbTcjOHRln14gCDy4EbBUIxlUcMs5Z4F1WX8E2XDZ0zIGHp+lPtIdtHnzTqtFIH+yFASfYxw=

Incorrect example in Ch 5

After "Because the if returns a value, we could also do something like this:" the println should be println! with appropriate arguments.

Chapter 09: First Vector Example Does not Work

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));                                                     
}

Long code lines are either cut off or wrapped weirdly

In the PDF version, any line of code longer than about 92 chars just gets cut off:

screen shot 2014-05-03 at 9 23 42 pm

Online, at about 95 chars, the line gets wrapped, sometimes in the middle of words:

screen shot 2014-05-03 at 9 25 00 pm

Same deal in the .mobi version in the amazon kindle for mac app:

screen shot 2014-05-03 at 9 36 45 pm

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 😭

Tilde

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 :)

cannot find type `int` in this scope

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.

Different output in Ch 6

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:"

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.