Hey, Mom! The Explanation.

Here's the permanent dedicated link to my first Hey, Mom! post and the explanation of the feature it contains.

Sunday, November 12, 2017

Hey, Mom! Talking to My Mother #859 - Getting started with RUST


Hey, Mom! Talking to My Mother #859 - Getting started with RUST

Hey Mom,

I have learned Java, C#, C, and Visual Basic (supposedly). I am on my way to learning Python and SQL, though these, Python especially, are getting me in touch with JSON, Javascript, Django, and others. RUST has been on my radar for a while, much like Kotlin, which I posted about the other day.

This posting is a way for me to consider learning Rust. I know you're not interested Mom and most of my regular readers are not, but these posts help me (my study, not my teaching), and they rate highly on number of hits per week.

So.... RUST...

https://www.infoworld.com/article/3234929/application-development/get-started-with-rust-the-language-for-safer-code.html?upd=1510593247733

Get started with Rust, the language for safer code



Here’s how to get your feet wet with using Rust’s tool chain, creating projects, working with third-party code, and managing libraries






Over the last couple of years, Rust has gone from a curiosity brewed up in the lab of a Mozilla employee to a strong contender for writing the next generation of native apps and bare-metal solutions. But those advances come from Rust providing its own tool chain and component management system—along with its own features and quirks.
This article walks through the basics of setting up a working environment in Rust, configuring an IDE, and making the most of the tool set Rust provides for app development.



The basics of the Rust development environment

Rust’s tool chain consists primarily of the Rust compiler, rustc, along with tools for managing a Rust installation. Because Rust is under constant development, the Rust tool chain is designed to be easy to keep up to date.

Software projects are often provided via multiple channels, to separate the stable and beta versions of the code. Rust’s tool chain works the same way, offering three channels for its tool chain:




  • Stable: Major point releases, which emerge every six weeks or so.
  • Beta: Candidates for the next major point release, which emerge more often.
  • Nightly: The most immediate build, with access to cutting-edge features but no guarantees as to their stability.
As developer Karol Kuczmarski has pointed out, it’s best to think of the nightly Rust channel as its own language. Some Rust features are only available in the nightly channel, and they can only be activated by special compiler directives. In other words, they won’t even compile on the beta or stable channels. That’s by design, because there’s no guarantee the nightly features will be supported anywhere else.
In short:
  1. Use stable for actual production work.
  2. Use beta to test current software against upcoming versions to see if anything may break in the upgrade.
  3. Only use nightly for sandboxed experiments with Rust’s newest features.

Choose a platform to develop in Rust

Rust supports all three major platforms—Windows, Linux, and MacOS—in both 32- and 64-bit incarnations, with official binaries for each. A slew of other platforms also have official binaries, but they don’t have the same level of automated testing coverage. These second-class platforms include ARMv6 and ARMv7 for iOS, Android, and Linux; MIPS Linux and MIPS64 Linux; and WebAssembly. Other platforms, like Solaris or Illumos, are supported through unofficial builds.
Rust’s development team has stated that it isn’t one of Rust’s missions to be as broadly portable as possible. For example, although Rust is available on many ARM architectures, it isn’t guaranteed that Rust will be officially supported on low-end hardware platforms.


That said, there should be a supported Rust build available for the vast majority of common, mainstream use cases—namely, 32- and 64-bit Windows, Linux, and MacOS.
If you’re planning to develop in Rust on Windows, keep your tool chains in mind. Rust supports two tool chains on Windows:
  • the native Microsoft Visual C (MSVC) ABI
  • the GNU ABI used by the GCC linker.
Because almost all C/C++ software built in Windows uses MSVC anyway, you’ll want to use the MSVC tool chain the vast majority of the time. If you ever need GCC, it’ll most likely be for interoperating with third-party libraries built in Windows with GCC.
The good news is that Rust’s tool chain management system lets you keep both MSVC and GCC tool chains installed, and it lets you switch between them on a project-by-project basis.
One of Rust’s compilation targets is WebAssembly, meaning you can write in Rust and deploy to a web browser. WebAssembly itself is still rough around the edges, and so is Rust’s support for it. But if you’re ambitious and want to get your hands messy, a project called Wargo can simplify the compilation process. (Note: Node.js is required.)

Start your Rust setup with rustup

Rust provides an all-in-one installer and tool chain maintenance system called rustupDownload rustup and run it; it’ll obtain the latest versions of the Rust tool chain and install them for you.


The most critical tools maintained by rustup are:
  • rustup itself. Whenever new versions of rustup or other tools are published, you can just run rustup update and have everything updated automatically.
  • rustc, the Rust compiler.
  • Cargo, Rust’s package and workspace manager.
By default, rustup installs Rust from the stable channel. If you want to use beta or nightly versions, you have to install those channels (for example, rustup install nightly), and set Rust to use them by default (rustup default nightly). You can also manually specify which channel to use when compiling a Rust application, so you don’t have to set and reset the default every time you move among projects.
You can also use rustup to install and maintain custom tool chains. These are typically used by unofficial, third-party builds of Rust for unsupported platforms, because those typically require their own linkers or other platform-specific tools.


rust updates IDG
rustup keeps all parts of your Rust tool chain updated to their most recent versions. Here, the nightly tool chain, with bleeding-edge and potentially unstable language components, is being updated separately from the stable version.

Configure your IDE for Rust

Despite Rust being a relatively new language, it’s already garnered strong support from many common IDEs. The state of such support is tracked at Rust's own website, areweideyet.com.
Making Rust work well with IDEs is an express goal of its development team, via a feature called the Rust Language Server, or RLS. RLS provides live feedback about the code in question from Rust’s own compiler, rather than from a third-party parser.




rust language server IDG
Rust’s Language Server project lets live feedback be provided to an IDE from the Rust compiler for the code you’re working with. Visual Studio Code, shown here, has some of the most complete support available for the Rust Language Server.

Here are the IDEs that support Rust:
  • Microsoft’s Visual Studio Code has a Rust language support extensioncreated by Rust’s own developer tools team. It is one of the best-supported IDEs for Rust. 
  • The RustDT package for Eclipse is nearly as powerful as Visual Studio Code.
  • If you’re a fan of Emacs or Vim, other developers like you have written Rust-specific add-ons for both editors. Emacs has a Rust-specific mode, and Vim has a plugin to provide syntax highlighting and formatting. However, neither one yet supports debugging with Rust nor integration with RLS.
  • IntelliJ Idea and Atom users can add plugins to round out Rust support.
  • Sublime Text has Rust syntax support out of the box, and plugins provide deeper support for other features.
  • A relatively new project, SolidOak, is a simple IDE specifically for Rust, although it’s currently available only for Linux and MacOS users.

Create your first Rust project

Rust projects are meant to have a consistent directory structure, with code and project metadata stored within them in certain ways. Code is stored in a src subdirectory, and details about the project are stored in Cargo.toml (the project’s basic information) and Cargo.lock (an automatically generated list of dependencies). You can create that directory structure and metadata by hand, but it’s easier just to use Rust’s own tools to do the job.



Rust’s Cargo tool manages both Rust projects and the libraries, or “crates,” they use. To spin up a new Rust project named my_project in its own directory, type cargo new my_project. (For C# developers working with .Net Core, think of the dotnet new command.) The new project appears in a subdirectory with that name, along with a basic project manifest—the Cargo.toml file—and a stub for the project’s source code, in a srcsubdirectory.
You can create a basic “hello world” project by placing a main.rs file in the src directory of the project:
fn main() {
    println!("Hello World!");
}
To build and run it, enter the root of the project directory and type cargo run. Note that by default, Cargo builds projects in debug mode. To run in release mode, use cargo run --release. Binaries are built in the target/debug or target/release subdirectory of a project, depending on which compilation profile you’re using.


rust compilation IDG
When a Rust project is compiled, all of its dependencies are obtained and compiled automatically as well. Detailed line-by-line feedback appears for anything that raises a warning or a full-blown error.




Work with Rust packages, aka “crates”

Package management is a key part of any modern programming environment. To that end, Rust provides “crates,” which are third-party libraries packaged for distribution with Rust’s tools. You can find crates in the official Rust package registry, Crates.io.
If your project has a dependency on a particular crate, you need to specify that crate by editing the project’s Cargo.toml file. The standard way to do this is manually—that is, by simply editing Cargo.toml directly with a text editor. The next time the project is rebuilt, Rust automatically obtains any needed dependencies.



When you build a Rust project that depends on external crates, Cargo looks for those crates on Crates.io by default; you don’t need to obtain them manually. You can also refer to crates in your project by URL rather than by crate name, in case you need a crate that isn’t hosted in the registry, such as something from a private repository.
Note that some crates will only install and build on Rust’s nightly channel, because they use experimental features not available in other channels. If you’re on the release channel and you try to install such a crate, you won’t get any warning until the compilation itself fails. Crate documentation usually mentions whether it requires the nightly channel or not, so read up before you compile.
Crates can come with binaries included. Some are command-line tools used in Rust development; others are general-purpose tools (such as ripgrep). To install one of these crates, just type cargo install . This isn’t the only way to distribute a binary created with Rust, but it’s a convenient way for Rust developers to obtain them as part of a workflow involving Rust tools.

Cross-compile Rust to another platform

Because Rust supports multiple tool chains, even in the same installation of Rust, you can compile Rust applications to a target OS and environment that’s different from the one you’re compiling on.
Such cross-compiling requires a tool chain on the platform you’re working on that matches the target platform. Sometimes, as with cross-compiling to Linux on Windows or vice versa, this involves little more than having the GCC linker. But other times, it’s more complex. For cross-compiling to MacOS, instance, you need the Xcode IDE libraries to finish the job.
Third-party tools offer some ways around these difficulties:
  • One such tool is Trust, a Travis CI and AppVeyor template that can automatically publish binary releases of a Rust project. It can built for Linux, Windows, and MacOS, although it requires use of the Travis CI and AppVeyor services, and it requires your project to be hosted on GitHub.
  • Another project, Cross, runs directly on an x86_64 Linux host, but provides what its creator describes as “zero-setup” cross-compiling to a wide variety of targets, including 64-bit Windows and MIPS.

Work with other Rust projects

A good way to get your legs with Rust is to check out a third-party project and work on it locally. The easy way to do that is just make a Git clone of a Rust project’s repository. As long as the repo has a Cargo.toml file in its root, it’ll be recognized by Cargo.
One thing Cargo can’t do, at least not yet, is make a local clone of a crate by itself. Most anyone doing serious work with Rust should have Git installed anyway, but you can add that functionality to Cargo directly via a third-party Cargo subcommand called cargo-clone.
Where to look for projects to tinker with and learn from? For starters, go to the Awesome Rust repository on GitHub. Many are useful on their own merits, not only for getting a leg up with Rust; these include Trust-DNS (a DNS server and client), Alacrity (a GPU-enhanced terminal emulator), and the MaidSafe decentralized data platform. Awesome Rust also lists many of the best crates and third-party tools to learn about and put to use.
If you’re hunting for a project to get involved with as a full-blown developer, check out Useful Rust Projects. Many of the projects listed there need developers or documentors, or are looking for new ownership.


+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Reflect and connect.

Have someone give you a kiss, and tell you that I love you, Mom.

I miss you so very much, Mom.

Talk to you tomorrow, Mom.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

- Days ago = 861 days ago

- Bloggery committed by chris tower - 1711.12 - 10:10

NEW (written 1708.27) NOTE on time: I am now in the same time zone as Google! So, when I post at 10:10 a.m. PDT to coincide with the time of your death, Mom, I am now actually posting late, so it's really 1:10 p.m. EDT. But I will continue to use the time stamp of 10:10 a.m. to remember the time of your death, Mom. I know this only matters to me, and to you, Mom.

No comments: