Installing Rust – InApps Technology is an article under the topic Software Development Many of you are most interested in today !! Today, let’s InApps.net learn Installing Rust – InApps Technology in today’s post !

Read more about Installing Rust – InApps Technology at Wikipedia

You can find content about Installing Rust – InApps Technology from the Wikipedia website

Last month I got a chance to pose some questions to the creator of Rust. But he’s not the only person thinking about Rust improving the security (and memory-safety) of our code. In 2017 TechCrunch urged engineers refactoring C code to begin replacing it with Rust, and the same year even open source guru Eric S. Raymond began hailing Rust as a plausible successor to C, as did Joyent Chief Technology Officer Byran Cantrill. And just last week Microsoft announced it was also exploring Rust as an alternative to C, as well as to C++.

So it seemed like high time that I got Rust up and running on my own system — to see just how easy (or how hard) it can be to install and run.

And to learn what I could about the unique advantages of Rust code…

Rust without Installation

The first thing I learned is that the Rust ecosystem is surprisingly robust — and that it’s possible to run Rust code without even installing anything. There’s a browser-based online “Rust Playground” where you can mess around with the language yourself. It starts you off with a pre-written “Hello world!” program, and dares you to take it from there.

 Hello World at Rust playground

That page features a lot of bells and whistles. The three dots on the far right pull up a menu that lets you select which Rust to run — either the earlier 2015 edition, or the 2018 edition — and whether or not you want to enable a debugging backtrace when it executes to give you even more visibility into how the program runs. There’s also a down-pointing arrow which brings up a menu for choosing which version of Rust to run — the current stable version, or the “beta” version (a more-recent version which gets updated every six weeks, according to the official Rust blog). And in addition, every 24 hours the last successful new build becomes the new “nightly” build, to “give early adopters access to unfinished features as we work on them.” This is also available through the same menu (via that down-pointing arrow).

But even the playground’s “Run” option has several choices. One choice lets you compile your code without running it — with or without testing it for errors — or to convert it to Assembly or to WebAssembly. And other choices let you convert your code to MIR (Rust’s “Mid-level Intermediate Representation”) or to LLVM IR (the intermediate representation for the Low-Level Virtual Machine that Rust uses as its backend).

Read More:   Prioritizing Risk with Risk Spotlight – InApps 2022

It’s fun to see how their simple “Hello World” program expands with each selection.

Some Hello World code in Assembly

But of course you can also create your own local installation of Rust, and Rust has its own installer/version management tool — called rustup. It’s available at Rust-lang.org on a slick web page which helpfully detects your operating system, and suggests the appropriate download.

Although if you access the page using the command-line browser Lynx in the Windows Subsystem for Linux, it apparently gets very confused, and displays messages for three different operating systems…

Rust install instructions via Lynx

rustup is officially described as a “toolchain multiplexer” that installs several of the important Rust tools. For example, rustup comes in handy when it’s time to update to a newer version of Rust. Just type:

rustup update

Rustup’s official documentation calls this “the essence of rustup”. But another neat thing about rustup is it makes it easy for you to manually switch between those three versions of the Rust compiler — the stable, beta, and nightly versions.

And if you want to make sure your rustup tool is up to date, you type…

rustup self update

So it seems deceptively simple to install Rust on a Windows system. You just download and run a file named Rustup-Init.exe

But of course, it wasn’t that easy…

Installation and a Detour

rustup checks for the necessary prerequisites, and lets you know if anything’s missing. In my case, I also needed to install the Microsoft C++ Build Tools — but Rustup-Init.exe told me I could get them by installing Microsoft’s Visual Studio IDE and then making sure that it also installed the C++ build tools — and even gave me the appropriate URL.

Rust install wants Microsoft C plus plus build tools
You can select the installation of build tools from Visual Studio’s workspace screen — although downloading them takes several long minutes…

The Visual Studio Installer alone was 67 megabytes, and Visual Studio Build Tools 2019 required 1.15GB more on my laptop — and took nearly 12 minutes to install. (It seemed to stall at page 83 of 89 pages installed — 35% of the status bar — and then suddenly shot up to 96%.)

Installing build tools with Visual Studio Installe

And when it was finished, a reboot was required.

But one reboot later, and I was running rustup

Getting Started With Cargo

The second thing I learned about Rust is there’s a couple of parts to it — leading to one more very important part of the installation process. rustup also installs the Cargo tool, which will launch the compiler for your code, run your code, and serve as a handy package manager for importing modules of pre-written Rust code — which will make everything easier. (And according to Rust’s official “Getting Started” page, Cargo also makes it easier to test your code, and to write documentation for it.)

Read More:   Pain-in-the-Neck New Year’s Resolutions for Developers – InApps Technology 2022

For the Windows version, rustup also adds the corresponding commands to your PATH environment variables — rustup, cargo, and rustc (the compiler).

Launching a command window, I ran the compiler’s --version command to prove that yes, it’s been installed. And there it was!

Rust version check

But if I’ve learned anything as a programmer, it’s that it’s never simple to write a “hello world” program in a compiled language. With Rust, first you have to create a new hello_world package (according to the documentation in Rust’s official Cargo Book.) It has a chapter titled “First Steps with Cargo.”

This can be done easily with a single Cargo command…

cargo new hello_world

Creating that package means creating a directory named hello_world with a manifest file (named Cargo.toml) which holds key-value pairs for the name, version, author, and edition of my humble “hello world” program.

making hello_world package

When running the compiler, it will look for a Cargo.toml file in your current directory to tell it which program to compile. (And it will stop with an error if the file isn’t found.) You don’t even have to specify the name of the program — it’s in the manifest. So just being in the appropriate directory is enough. You just type cargo build.

building hello world (cropped).

That cargo new command also created a separate src subdirectory where the actual code will go. I thought I was going to have to type in some lines of code (to print out “hello world” on my screen) — but apparently not. Cargo created a main.rs file in my src directory which already contains an entire main function — and which already includes the appropriate print statement.

fn main() {
println!("Hello, world!");
}

Did Cargo guess that since I was making a package named “hello_world,” I must want it to print out “hello world”?

No. It’s apparently the default stub that appears in every src directory’s main file. I tested this by creating a package named goodbye_world — and Cargo still included the exact same code in the main file it created. (Including a println statement that prints out “Hello, world!”)

So it’s a feature, not a bug — and the pre-written code now stares tantalizingly from my hard drive, daring me to finally compile it into my first executable Rust program. (Or, as the Cargo book explains, “Cargo generated a ‘hello world’ for us. Let’s compile it.”)

A Surprise Ending

Er, and unfortunately, here’s where the Cargo Book failed me. It told me that to run the program, I simply needed to type:

Read More:   Chef Offers Habitat, a New Kind of Application Automation – InApps 2022

./target/debug/hello_world

Nope.

Rust error - not recognized

Fortunately, the Cargo Book also provides an alternate (and simpler) way of running Rust programs: just type cargo run in the appropriate directory — which will compile and run your program, all in one glorious step.

Hello World run from Rust on a Windows command line

It was glorious.

I did the building-and-running command a few more times, just because I could, just to prove to myself that it was really working.

And to savor the fact that I was finally running my very first Rust program…

List of Keywords users find our article on Google:

visual studio installer
wawa menu
refactoring guru
visual studio build tools
rust playground
site:www.inapps.net
rust wikipedia
visual studio 2019 installer
visual studio installer not working
visual studio 2017 installer
rust installation
eve workbench
cargo toml
rust lang cargo
build tools for visual studio 2019
rustlabs
visual c++ build tools 2017
install visual studio
rust labs
detour wikipedia
build tools for visual studio
command-line rust
visual c++ tools
visual c++ windows build tools
rust docs
rust book
rust envoy
install rust compiler
rust edition 2022
visual studio 2022 rust
wikipedia rust
rust version
rust dev blog
rust enable feature
rust get current directory
cargo environment variables
rust crates
rust without cargo
rust print working directory
visual studio not installed; this is necessary for windows development.
rust package
lynx studio technology
microsoft build tools 2019
rust instal
visual studio build tools 2019
install visual studio 2019
build tools for visual studio 2017
error: could not find any visual studio installation to use
refactor guru
rustlang jobs
rust cargo version
rust backtrace
visual c++ build tools 2015
rust windows
visual studio 2019 build tools
rust core error
visual studio 2019 c compiler
visual c++ 2015 build tools
could not install visual studio build tools
visual studio build tool
visual studio c++ tools
how to get workbench level 1 rust
microsoft c++
rust for windows
rust workbench
glorious workbench review
rust build rs
rust cargo commands
visual studio install
llvm ir
rust any type
rust cargo update
microsoft visual c build tools
visual studio build
how to run program in visual studio
play.rust-lang
rust online compiler
rust specify type
cargo build.rs
workbench rust
rust give command
rust test framework
updating visual studio 2019 to 2022
visual studio c++ build tools
function type rust
just rust
lynx plus security system
simple stories hello today
update cargo version
visual c++ 2019 build tools
visual studio check for updates
visual studio installer download
lynx recruitment
microsoft visual c ++
phone number backtrace
rust write to file
visual studio tools
wawa food menu
gotrust id
lynx logo design
windows c++ build tools

Source: InApps.net

Rate this post
Content writer

Let’s create the next big thing together!

Coming together is a beginning. Keeping together is progress. Working together is success.

Let’s talk

Get a custom Proposal

Please fill in your information and your need to get a suitable solution.

    You need to enter your email to download

      Success. Downloading...