A word from our sponsors

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
prog:rust:intro [2024/06/24 10:33] Frank Fegertprog:rust:intro [2024/06/24 12:48] (current) Frank Fegert
Line 14: Line 14:
  
 [[https://www.rust-lang.org/]]\\ [[https://www.rust-lang.org/]]\\
 +https://www.rust-lang.org/learn|Rust Documentation - Learning Rust]]\\
 +[[https://www.rust-lang.org/learn/get-started|Rust Documentation - Getting started]]\\
 +[[https://crates.io|The Rust community’s crate registry]]\\
  
 /* [[]]\\ */ /* [[]]\\ */
Line 38: Line 41:
  
 ====== Getting Help ====== ====== Getting Help ======
- 
-FIXME 
  
 Manual pages:  Manual pages: 
  
 <cli> <cli>
-user@host:~$ +user@host:~$ man 1 rustc 
 +user@host:~$ man 1 rustdoc 
 +user@host:~$ man 1 cargo 
 +user@host:~$ man 1 cargo-<SUBCOMMAND> 
 +</cli> 
 + 
 +Builtin //Cargo// help:  
 + 
 +<cli> 
 +user@host:~$ cargo help 
 +user@host:~$ cargo help <SUBCOMMAND> 
 +user@host:~$ cargo <SUBCOMMAND> --help
 </cli> </cli>
  
 ====== Install ====== ====== Install ======
  
-FIXME+To install //Rust// and its build toolchain and package manager //Cargo// on Debian:
  
-To install //// on Debian: +<cli> 
 +root@host:~$ apt-get -y install rustc cargo 
 +</cli>  
 + 
 +To install //Rust// and its build toolchain and package manager //Cargo// from a more recent version on Debian:
  
 <cli> <cli>
-root@host:~$ +root@host:~$ apt-get -y install rustc-mozilla cargo-mozilla
 </cli>  </cli> 
  
Line 62: Line 78:
  
 ====== Usage ====== ====== Usage ======
 +
 +===== Creating a new project =====
 +
 +<cli>
 +user@host:~$ cargo new hello_world
 +</cli> 
 +
 +===== Compile and run a project =====
 +
 +Compile and run a project *with* debugging information:
 +
 +<cli>
 +user@host:~$ cd hello_world
 +user@host:~/hello_world$ cargo run
 +user@host:~/hello_world$ du -sm target/debug/hello_world
 +</cli> 
 +
 +Compile and run a project *optimized* and *without* debugging information:
 +
 +<cli>
 +user@host:~/hello_world$ cargo run --release
 +</cli> 
 +
 +===== Clean a project =====
 +
 +Clean a project from the artefacts of a previous compile and run:
 +
 +<cli>
 +user@host:~/hello_world$ cargo clean
 +</cli> 
 +
 +===== Add a dependency to a project =====
 +
 +Add a external library dependency to a project. E.g. ''ferris-says'':
 +
 +<cli>
 +user@host:~/hello_world$ cargo add ferris-says
 +</cli> 
 +
 +Manually add a external library dependency to a project. E.g. ''ferris-says'':
 +
 +<cli>
 +user@host:~/hello_world$ vi Cargo.toml
 +</cli> 
 +
 +File contents:
 +
 +<file config hello_world/Cargo.toml>
 +[...]
 +
 +[dependencies]
 +ferris-says = "0.2.1"
 +</file>
 +
 +Update the projects main code:
 +
 +<cli>
 +user@host:~/hello_world$ vi src/main.rs
 +</cli> 
 +
 +File contents:
 +
 +<file config hello_world/src/main.rs>
 +use ferris_says::say;
 +use std::io::{stdout, BufWriter};
 +
 +fn main() {
 +    let stdout = stdout();
 +    let message = b"Hello fellow Rustaceans!";
 +    let width = 24;
 +
 +    let mut writer = BufWriter::new(stdout.lock());
 +    say(message, width, &mut writer).unwrap();
 +}
 +</file>
 +
 +Compile and run the updated project:
 +
 +<cli>
 +user@host:~/hello_world$ cargo run
 +</cli> 
 +
 +===== Set a dependency to a specific version in a project =====
 +
 +Set a first and second level dependency to a specific version in a project:
 +
 +<cli>
 +user@host:~/hello_world$ cargo update -p unicode-width --precise 0.1.7 
 +user@host:~/hello_world$ cargo update -p smawk --precise 0.3.0
 +</cli> 
  
 FIXME FIXME