Rust: Difference between revisions

From 太極
Jump to navigation Jump to search
No edit summary
 
(2 intermediate revisions by the same user not shown)
Line 1: Line 1:
[https://www.2daygeek.com/how-to-install-rust-programming-language-in-linux/ How To Install Rust Programming Language In Linux]
= Install =
* [https://www.2daygeek.com/how-to-install-rust-programming-language-in-linux/ How To Install Rust Programming Language In Linux]
<ul>
<li>
[https://www.osradar.com/install-rust-programming-language-ubuntu-debian/ Install Rust on Ubuntu 20.04 / Debian 10] and hello world example.
<pre>
$ curl https://sh.rustup.rs -sSf | sh
Welcome to Rust!


This will download and install the official compiler for the Rust
programming language, and its package manager, Cargo.
Rustup metadata and toolchains will be installed into the Rustup
home directory, located at:
  /home/brb/.rustup
This can be modified with the RUSTUP_HOME environment variable.
The Cargo home directory located at:
  /home/brb/.cargo
This can be modified with the CARGO_HOME environment variable.
The cargo, rustc, rustup and other commands will be added to
Cargo's bin directory, located at:
  /home/brb/.cargo/bin
This path will then be added to your PATH environment variable by
modifying the profile file located at:
  /home/brb/.profile
You can uninstall at any time with rustup self uninstall and
these changes will be reverted.
Current installation options:
  default host triple: x86_64-unknown-linux-gnu
    default toolchain: stable (default)
              profile: default
  modify PATH variable: yes
1) Proceed with installation (default)
2) Customize installation
3) Cancel installation
>
...
  stable installed - rustc 1.48.0 (7eac88abb 2020-11-16)
Rust is installed now. Great!
To get started you need Cargo's bin directory ($HOME/.cargo/bin) in your PATH
environment variable. Next time you log in this will be done
automatically.
To configure your current shell run source $HOME/.cargo/env
$ source $HOME/.cargo/env
$ which cargo
/home/brb/.cargo/bin/cargo
</pre>
</li>
</ul>
= Examples =
== Calculator + Github actions ==
[https://www.techbeatly.com/2020/07/self-hosted-runners-for-github-actions.html Self hosted runners for GitHub Actions]
<pre>
$ cargo build --verbose
$ cargo test --verbose
$ rustc  calculator.rs
$ ./calculator
expr:
5*9
result: 45
</pre>
== Bandwich ==
[https://github.com/imsnif/bandwhich bandwhich]
[https://github.com/imsnif/bandwhich bandwhich]
== A simple guessing the number game ==
[https://opensource.com/article/20/12/learn-rust Learn Rust by writing a simple game]

Latest revision as of 16:21, 3 January 2021

Install

  • Install Rust on Ubuntu 20.04 / Debian 10 and hello world example.
    $ curl https://sh.rustup.rs -sSf | sh
    Welcome to Rust!
    
    This will download and install the official compiler for the Rust
    programming language, and its package manager, Cargo.
    
    Rustup metadata and toolchains will be installed into the Rustup
    home directory, located at:
    
      /home/brb/.rustup
    
    This can be modified with the RUSTUP_HOME environment variable.
    
    The Cargo home directory located at:
    
      /home/brb/.cargo
    
    This can be modified with the CARGO_HOME environment variable.
    
    The cargo, rustc, rustup and other commands will be added to
    Cargo's bin directory, located at:
    
      /home/brb/.cargo/bin
    
    This path will then be added to your PATH environment variable by
    modifying the profile file located at:
    
      /home/brb/.profile
    
    You can uninstall at any time with rustup self uninstall and
    these changes will be reverted.
    
    Current installation options:
    
    
       default host triple: x86_64-unknown-linux-gnu
         default toolchain: stable (default)
                   profile: default
      modify PATH variable: yes
    
    1) Proceed with installation (default)
    2) Customize installation
    3) Cancel installation
    >
    ...
      stable installed - rustc 1.48.0 (7eac88abb 2020-11-16)
    
    Rust is installed now. Great!
    
    To get started you need Cargo's bin directory ($HOME/.cargo/bin) in your PATH
    environment variable. Next time you log in this will be done
    automatically.
    
    To configure your current shell run source $HOME/.cargo/env
    $ source $HOME/.cargo/env
    $ which cargo
    /home/brb/.cargo/bin/cargo
    

Examples

Calculator + Github actions

Self hosted runners for GitHub Actions

$ cargo build --verbose
$ cargo test --verbose
$ rustc  calculator.rs
$ ./calculator 
expr:
5*9
	result: 45

Bandwich

bandwhich

A simple guessing the number game

Learn Rust by writing a simple game