Giter Club home page Giter Club logo

rust-cookbook's Introduction

A Rust Cookbook โ€ƒ Build Status travis

Read it here.

This Rust Cookbook is a collection of simple Rust examples that demonstrate good practices to accomplish common programming tasks, using the crates of the Rust ecosystem.

These examples are complete, and suitable for copying directly into new cargo projects. They are tested and guaranteed to work.

Read it offline

If you'd like to read it locally:

$ git clone https://github.com/rust-lang-nursery/rust-cookbook
$ cd rust-cookbook
$ cargo install mdbook --vers "0.4.5"
$ mdbook serve --open

The output can also be opened from the book subdirectory in your web browser.

$ xdg-open ./book/index.html # linux
$ start .\book\index.html    # windows
$ open ./book/index.html     # mac

Contributing

This project is intended to be easy for new Rust programmers to contribute to, and an easy way to get involved with the Rust community. It needs and welcomes help.

For details see CONTRIBUTING.md on GitHub.

License CC0-badge

Rust Cookbook is licensed under Creative Commons Zero v1.0 Universal License (LICENSE-CC0 or https://creativecommons.org/publicdomain/zero/1.0/legalcode)

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in Rust Cookbook by you, as defined in the CC0-1.0 license, shall be dedicated to the public domain and licensed as above, without any additional terms or conditions.

rust-cookbook's People

Contributors

andygauge avatar baishuai avatar bostelk avatar branderson avatar brson avatar budziq avatar charlesetc avatar dhharris avatar dominikwin avatar dtolnay avatar gsquire avatar j-haj avatar jaemk avatar jameshinshelwood avatar joe1994 avatar jturner314 avatar juli1 avatar kappadistributive avatar lnicola avatar ludwigpacifici avatar michael-f-bryan avatar mikeastock avatar ophirr33 avatar paulirotta avatar rap2hpoutre avatar trentspi avatar tshepang avatar vishalsodani avatar yandexx avatar yogesum 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  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

rust-cookbook's Issues

Log an error message to the console

Using env_logger. This is different from #95 in that it should show making a function call that returns a Result, matching on it, and logging in the error case with the error value included in the message.

Pilliage the perl cookbook for ideas

Perl Cookbook has a good reputation, but I have never read it. Give it a skim at least, then figure out which of their examples make sense in the Rust world, and produce a list of example use case statements to feed into the cookbook.

Badges are not synchronised with Cargo.toml

Badges obtained from shields.io are always for the latest version available on crates.io
https://img.shields.io/crates/v/clap.svg?label=clap clap currently shows 2.24.1 while in committed Cargo.lock clap has version 2.23.3.

This is somewhat low priority ATM but I am sure that it will become a problem once breaking changes of cookbook dependencies are published. Users will likely get build errors from posted examples misguided by the badge version incompatible with cookbook Cargo.lock.

Imho It would be best to:

  • Have travis check versions - possibly with https://crates.io/crates/cargo-outdated (and eagerly update if there are no conflicts/failed tests?)
  • Have badges reflect the actual version in Cargo.lock - currently i have no idea how to manage that

Miscellaneous cookbook ideas

The Perl cookbook or Python cookbook could be a good source of inspiration.

Implement Rand crate examples in Basics section

Hi, I did not see issue for the missing Rand crates examples in Basics section so I went ahead and opened it here (I hope it's ok)

  • Generate random floating point numbers
  • Generate random values of a custom type

I would like to create a PR for both of these snippets.
Also I would suggest to create another example Generate random numbers within a range as this seams to be a relatively common usecase.

cc @brson

incorrect formatting of raw strings

the code formatting for many of the snippets 'breaks' when it sees quote-pairs inside raw strings r#"like "this" eg"#, it would unhighlight the word 'this'. probably because it's not highlighting the raw stirng just the "" pairs between the ## 's

I know this is probably not a bug with /this/ repository but I wouldn't know where to look to actually fix it

Cookbook ideas for using a RESTful service

All major websites and many services provide restful apis. Using those has become a very important topic, be it for retrieving information from websites, interacting with common third-party service or communicating in an internal network.

Ideally, a whole chapter should be dedicated to this topic. It should explaining the following subjects, which are ordered in descending priority:

Iterate through paginated requests

The crates.io API would be a good way to demonstrate this. A lot of their endpoints are limited to 100 elements per query, with a page=2 parameter to see more elements.

curl -sS \
  -H 'Content-Type: application/json' \
  'https://crates.io/api/v1/crates/serde/reverse_dependencies?per_page=100&page=2'

TOC Tables and badges are not consistent between files

The tables in concurency.md, encoding.md and app.md are not consistent with main TOC in intro.md (categories are missing). I am assuming that these should be mirrored.
Moreover most of examples except in basics.md are missing at least one badge.

I can solve it later today.

Handle a rate-limited API

Hitting a rate limit may either return an error for the request or return a JSON body that is different from the usual. Let's show how to deal with one or both of these cases.

Actually write about.html

Most of this page is not written!

This is pretty important for appearances, so I'll try to get to it soon, but patches still welcome. Speak up on thread if you plan to write any sections.

Cookbook ideas for reqwest crate

Come up with ideas for nice introductory examples of using reqwest, possibly in combination with other crates, that would be good to show in the Rust Cookbook. Please leave a comment here with your ideas! You don't necessarily have to write the example code yourself but PRs are always welcome!

Crate evaluation thread on internals.rust-lang.org

Cookbook ideas for log crate

Write examples for these use cases following the existing precedent and guidelines in CONTRIBUTING.md

Crate evaluation for log: See https://internals.rust-lang.org/t/crate-evaluation-for-2017-05-16-log/5185

Suggest ideas for other examples here if you have them!

Make a Travis build that tests with all dependencies = "*"

Basically replace all version requirements in Cargo.toml under [dependencies] with "*", then cargo test. This will notify us when a crate releases a new major version that is incompatible with our example code, meaning the example needs to be updated.

RFC - error_chain in some examples is quite noisy

@dtolnay Hi after switching all examples with fn run() to error_chain some of the examples became quite noisy eg http://localhost:3000/net.html#parse-a-url-from-a-string-to-a-url-type
has 8 lines of code to 9 lines of error_chain maiking it hard to read

I think that we could have best of both worlds (completely copy-pastable examples and minimal noise) if we have used the expand collapse button (currently hidden along with play button) and hide the error_chain and main boiler plate by default (and be able to show it on click).

I will prepare a minimal PR for your consideration

Polish the presentation for launch

Let's take what we have and make it look real nice.

Some ideas:

  • Create an "Introduction" prose chapter, and sink the error handling discussion into that.
  • Write a brief, motivating introduction
  • Turn the TOC into a flat list of domains, like "File I/O", "Concurrency", "Math", "Processes", etc. each
    with its own page, each page is a flat list of use cases with accompanying examples
  • Fill out the contributing page
  • Make the alignment of badges more aesthetic

cc @branderson @dhharris @trentspi

Broken Links in CONTRIBUTING.md

According to CONTRIBUTING.md:

This project is intended to be simple to contribute to, and to always have obvious next work items available.

That means it's probably important to let you know that the links and some of the formatting are broken in the contributing file. This is probably a really easy fix for someone looking to contribute. ๐Ÿ˜„

Issues I found while reading through CONTRIBUTING.md:

  • [libz blitz] does not link to anything (this link is used several times throughout the file)
  • [crate-tasks] does not link to anything
  • ["how to read this book"] does not link to anything
  • The Adding an example link at the top of the file in the navigation links does not work
  • The "a note about crate representation" link in Finding what to contribute is broken and the section on the page it links to is empty
    • The section being empty is a bigger bug than the link being broken because it's not easy to know how to contribute if you were relying on that section to know which crates are being represented in the cookbook. I'm bringing this up because the file explicitly says:

      If at any time there is not something obvious to contribute, that is a bug.

  • The "A note about error handling" link in Example Guidelines is broken

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.