Giter Club home page Giter Club logo

node-to-rust's Introduction

From JavaScript to Rust ebook

This repository houses an ebook-ified version of the 24+ post series started on vino.dev.

How to build

The ebook is built using asciidoctor and requires ruby >2.3.

Install the ruby dependencies via make deps

$ make deps

Build a PDF via the command make book

$ make book

Running code and projects

All code are housed in the src/ directory.

Day 4

  • cargo run -p day-4-hello-world
  • cargo run -p day-4-strings-wtf-1 - intentionally does not compile.
  • cargo run -p day-4-strings-wtf-2 - intentionally does not compile.

Day 5

Reassigning

  • JS: node javascript/day-5/let-vs-const/reassigning.js
  • Rust: cargo run -p day-5-let-vs-const --bin reassigning
  • cargo run -p day-5-let-vs-const --bin reassigning-wrong-type - intentionally does not compile

Borrowing

  • cargo run -p day-5-borrowing --bin borrow
  • cargo run -p day-5-borrowing --bin mutable-borrow - intentionally does not compile

Day 6

  • cargo run -p day-6-loads-of-strs --bin 200-unique-prints
  • cargo run -p day-6-loads-of-strs --bin 200-prints
  • cargo run -p day-6-loads-of-strs --bin 200-empty-prints
  • cargo run -p day-6-loads-of-strs --bin one-print

Day 7

Syntax

  • cargo run -p day-7-syntax

Day 8

Maps

  • ts-node javascript/day-8/src/maps.ts
  • cargo run -p day-8-maps

Structs

  • ts-node javascript/day-8/src/structs.ts
  • cargo run -p day-8-structs

Day 9

Day 10

Day 11

Modules

  • cargo run -p day-11-modules --bin nested-submodules
  • cargo run -p day-11-traffic-light

Day 12

  • cargo run -p day-12-impl-tostring
  • cargo run -p day-12-impl-asref-str

Day 13

  • cargo run -p day-13-option
  • cargo run -p day-13-result
  • cargo run -p day-13-question-mark

Day 14

From/Into

  • cargo run -p day-14-from-into

Errors

These examples require setting an environment variable. How to do that in your environment might look different.

  • MARKDOWN=README.md cargo run -p day-14-boxed-errors
  • MARKDOWN=README.md cargo run -p day-14-custom-error-type
  • MARKDOWN=README.md cargo run -p day-14-thiserror
  • MARKDOWN=README.md cargo run -p day-14-error-chain
  • MARKDOWN=README.md cargo run -p day-14-snafu

Day 16

Closures

  • cargo run -p day-15-closures

Day 16

Type differences

  • cargo run -p day-16-type-differences --bin impl-owned
  • cargo run -p day-16-type-differences --bin impl-borrowed

'static

  • cargo run -p day-16-static - intentionally does not compile
  • cargo run -p day-16-static-bounds - intentionally does not compile

Lifetime elision

  • cargo run -p day-16-elision

Unsafe pointers

  • cargo run -p day-16-unsafe-pointers

Day 17

Arrays

  • cargo run -p day-17-arrays
  • ts-node javascript/day-17/src/arrays.ts

Iterators

  • cargo run -p day-17-iterators
  • ts-node javascript/day-17/src/iterators.ts

Names example

  • cargo run -p day-17-names

Day 18

  • cargo run -p day-18-async --bin send-sync
  • cargo run -p day-18-async --bin simple
  • cargo run -p day-18-async --bin lazy
  • cargo run -p day-18-async --bin fs
  • cargo run -p day-18-async --bin async-blocks

Day 19

First you must cd into crates/day-19/project

  • cargo test
  • cargo run -p cli

Day 20

First you must cd into crates/day-20/project

  • RUST_LOG=cli=debug cargo run -p cli

Day 21

waPC runner

First you must cd into crates/day-21/project

  • cargo run -p cli -- crates/my-lib/tests/test.wasm hello "Potter"

waPC guest (hello)

First you must cd into crates/day-21/wapc-guest

  • Build with make

Day 22

Serde

  • cargo run -p day-22-serde

waPC runner

First you must cd into crates/day-22/project

  • cargo run -p cli -- crates/my-lib/tests/test.wasm hello hello.json
  • cargo run -p cli -- ./blog.wasm render ./blog.json

waPC guest (blog)

First you must cd into crates/day-22/wapc-guest

  • Build with make

Day 23

  • cargo run -p day-23-rc-arc --bin references
  • cargo run -p day-23-rc-arc --bin rc
  • cargo run -p day-23-rc-arc --bin arc
  • cargo run -p day-23-rc-arc --bin rwlock
  • cargo run -p day-23-rc-arc --bin async - intentionally does not compile

License

Book: Creative Commons BY-NC 4.0 Code: Creative Commons BY 4.0

node-to-rust's People

Contributors

deptno avatar hickatheworld avatar johnnycopes avatar jsoverson avatar liby avatar michaelficarra avatar olegrjumin avatar syohex avatar trongtai37 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

node-to-rust's Issues

Day 20: CLI Arguments and Logging, a issue with the chapter

As mentioned in the section on Adding CLI Arguments

  • follow the steps and you will see the following output on the command line
cargo run -p cli -- --help
wasm-runner 0.1.0
Sample project from https://vino.dev/blog/node-to-rust-day-1-rustup/

USAGE:
    cli

FLAGS:
    -h, --help       Prints help information
    -V, --version    Prints version information
The example code at this point should look like this
  use my_lib::Module;
  use structopt::{clap::AppSettings, StructOpt};

  #[macro_use]
  extern crate log;

  #[derive(StructOpt)]
  #[structopt(
      name = "wasm-runner",
      about = "Sample project from https://vino.dev/blog/node-to-rust-day-1-rustup/",
      global_settings(&[
          AppSettings::ColoredHelp
      ]),
  )]
  struct CliOptions {}

  fn main() {
      env_logger::init();
      debug!("Initialized logger");

      match Module::from_file("./module.wasm") {
          Ok(_) => {
              info!("Module loaded");
          }
          Err(e) => {
              error!("Module failed to load: {}", e);
          }
      }
  }

Now when we run our cli we see… nothing at all.

No issue.

I just want to thank you for your series mate !
Great read, keep it up.
🥇

Day 9: getState() return type differences

When describing the solution for getState, initially the implementation pub fn get_state(&self) -> &String is given along with a usefull explanation which matches the struct types.

But for the "full code" implementation immediately following, it changes to pub fn get_state(&self) -> &str which I found confusing since the distinction between them is not covered and the apparent String -> &str "cohersion" in the second version is not made clear inline.

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.