写给前端看的Rust教程(1)从nvm到rust

·  阅读 2052
写给前端看的Rust教程(1)从nvm到rust

原文:24 days from node.js to Rust

前言

Rust的学习曲线非常陡峭,即便是系统程序员学习起来也会遇到困难。鉴于目前RustWebAssembly的支持是最好的,对于web程序员来说,你可以将CPU密集型的JavaScript逻辑用Rust重写,然后再用WebAssembly来运行,JavaScriptRust的结合将会让你获得驾驭一切的力量

本教程不追求大而全,读者最好有Node.js的使用经验,文中会不断拿JavaScriptTypeScriptRust中的对应部分相类比来帮助读者更好的理解

此外,本文不能代替 The Rust Book ,这个文档始终是你学习rust最应该阅读的,而且是反复阅读。一些 The Rust Book 中有的内容我们不会再详细介绍了,如过遇到,我们会给出相应的链接

正文

Node.js世界,我们用 nvmnvm-windows 来做不同版本Node.js的无缝安装和切换。在Rust世界中对应的是 rustup

rustup负责管理Rust的安装以及额外的编译目标(如WebAssembly),除此之外还包含一些核心的工具,如cargoRust版的npm)、clippyRust版的eslint)、rustfmtRust版的prettier)。在使用Rust之前我们首先安装好Rustup[安装连接],安装完毕之后,执行rustup命令会看到如下的结果:

$ rustup
rustup 1.24.3 (ce5817a94 2021-05-31)
The Rust toolchain installer

USAGE:
    rustup [FLAGS] [+toolchain] <SUBCOMMAND>

FLAGS:
    -v, --verbose    Enable verbose output
    -q, --quiet      Disable progress output
    -h, --help       Prints help information
    -V, --version    Prints version information

ARGS:
    <+toolchain>    release channel (e.g. +stable) or custom toolchain to set override

SUBCOMMANDS:
    show           Show the active and installed toolchains or profiles
    update         Update Rust toolchains and rustup
    check          Check for updates to Rust toolchains and rustup
    default        Set the default toolchain
    toolchain      Modify or query the installed toolchains
    target         Modify a toolchain's supported targets
    component      Modify a toolchain's installed components
    override       Modify directory toolchain overrides
    run            Run a command with an environment configured for a given toolchain
    which          Display which binary will be run for a given command
    doc            Open the documentation for the current toolchain
    man            View the man page for a given command
    self           Modify the rustup installation
    set            Alter rustup settings
    completions    Generate tab-completion scripts for your shell
    help           Prints this message or the help of the given subcommand(s)

DISCUSSION:
    Rustup installs The Rust Programming Language from the official
    release channels, enabling you to easily switch between stable,
    beta, and nightly compilers and keep them updated. It makes
    cross-compiling simpler with binary builds of the standard library
    for common platforms.

    If you are new to Rust consider running `rustup doc --book` to
    learn Rust.
复制代码

默认情况下,rustup会安装最新版本的rustcargo

$ rustc --version
rustc 1.57.0 (59eed8a2a 2021-11-01)

$ cargo --version
cargo 1.56.0 (4ed5d137b 2021-10-04)
复制代码

更多

分类:
前端
标签:
分类:
前端
标签:
收藏成功!
已添加到「」, 点击更改