Differences between revisions 15 and 17 (spanning 2 versions)
Revision 15 as of 2024-05-31 21:51:08
Size: 2705
Editor: ?LeandroDoctors
Comment: format code block
Revision 17 as of 2024-08-29 05:52:04
Size: 2868
Editor: PaulWise
Comment: typo
Deletions are marked like this. Additions are marked like this.
Line 40: Line 40:
=== Using Rust Analyzer ===
Line 41: Line 42:


=== Using Rust Analyzer ===
/!\ The Rust Analyzer [[https://rust-analyzer.github.io/manual.html#security|should not be used with untrusted Rust source code because it executes arbitrary code]].

As Wikipedia says, Rust is a multi-paradigm, high-level, general-purpose programming language designed for performance and safety, especially safe concurrency. Rust is syntactically similar to C++, but can guarantee memory safety by using a borrow checker to validate references. Rust achieves memory safety without garbage collection, and reference counting is optional.

Developing with Rust on Debian

Debian ships rustc (the Rust compiler), cargo (the Rust package manager and build system), rustfmt (the Rust code formatter), a number of packages written in Rust or including modules written in Rust, and a growing number of Rust crates (Rust libraries).

Using crates from Debian

Due to the way Rust and the Rust crates are packaged in Debian, packages shipping Rust crates are mainly useful when packaging other crates or Rust-based software for Debian. While you can use them for everyday development with Rust, their main use is as dependencies for other applications since Debian doesn't allow downloading source code at build-time.

To only use the local (Debian) version of crates, place the following snippet in a .cargo/config file at your projects' root:

[source]
[source.debian-packages]
directory = "/usr/share/cargo/registry"
[source.crates-io]
replace-with = "debian-packages"

.. and install any of its crate dependencies via apt install librust-CRATE-dev  (or declare them in debian/control if it's for a package).

Using crates from the Internet

For everyday Rust development, you may find rustup useful, as it provides a convenient way to install Rust toolchains and switch between them globally or on a per-project basis.

# Install rustup
$ sudo apt install rustup

# Use the latest stable Rust release from upstream
$ rustup default stable

# Read the official documentation "The Rust Programming Language"
$ rustup docs --book

Using Rust Analyzer

/!\ The Rust Analyzer should not be used with untrusted Rust source code because it executes arbitrary code.

The Rust Analyzer extension for VS Code comes with the binary of the analyzer, but it doesn’t come with the source code of the Rust standard library, which is required for the analyzer to operate. Debian ships the source code as rust-src.

Other editors require downloading the binary manually. Packaging is requested in 1052319.

Packaging Rust applications and crates

For packaging:


CategorySoftware | CategoryProgramming