The new version of Rust 1.30.0 arrives with improved module system and more

Rust logo with gear

Rust or rust-lang is a fairly modern and open source programming language, in addition to being multiplatform, fast and designed to replace C and C ++.

It was created by Mozilla and it has high-level abstraction to please also those who come from C # and Java.

And that's not all, we can see many interesting features that do not appear in other programming languages, such as zero cost abastractions, motion sematics, guaranteed memory security, reduced execution time, etc.

About the new version of Rust 1.30.0

Rust developers have announced a new version 1.30.0 of your programming language.

This new version of the language, adds new types of procedural macros, defines their validity as "use", and improves the module system.

Attributes and function-like procedure macros are the newest additions to Rust 1.30.0.

The former are similar to custom Derive macros, but allow you to define new and custom attributes additional instead of the attribute "# [Derive]", allowing you to create your own new custom attributes.

Also, they not only work for structures and enums, but also for functions.

Other changes and innovations explain the official announcement of the current version, as well as the few detailed release notes on Github.

About "rustup update stable" may be the new Rust version.

Rust 1.30 expands on this by adding the ability to define two other advanced macro types, "Attribute-like procedural macros" and "Function-like procedural macros".

They're also more flexible - deriving only works for structures and enums, but attributes can go elsewhere, like functions.

As an example of using an attribute-like macro, you might have something like this when using a web application framework.

Function-like procedural macros define macros that look like function calls. In the case of SQL, this could be something like this:

let sql = sql! (SELECT * FROM posts WHERE id = 1); 

The macro, recognizable by the exclamation point, would parse the embedded SQL statement and verify its syntactic correctness, according to the announcement of the new version. It can be defined through:

# [Proc_macro]

pub fn sql (input: TokenStream) -> TokenStream {...} 

Here, the function-like macro follows the Derive macro by evaluating the code in parentheses and returning the code to be generated.

At the same time, the above notation "# [Macro_use]" used to use external box macros. Replaces the use of "use."

Improved module system.

Not less important, the developers have improved the module system or changed some cumbersome and unusual syntax rules.

Until now, problems have arisen when developers move a function to a submodule without an explicit "use" prefix.

Rest 1.30.0

Rust recently checks the path to automatically detect if it is an external box. If so, it will be used regardless of the current position in the module hierarchy.

Rust also adapts to the use of the keyword «crate». For example, "use crate :: foo :: bar;" indicates that the path to the "bar" function starts from the foo module in the root directory of the box, not from the current directory.

This allows, for example, to call the function of module number 1 outside of the function of module number 2 without having to use "use".

How to install Rust 1.30.0 on Linux?

For those who are interested in installing Rust on their systems, they should download the necessary package in our distro, for this we will use curl:

curl https://sh.rustup.rs -sSf | sh 

With this we access the site and run the script.

A series of options will open to us in our terminal and we must answer appropriately. You must press 1 to continue the installation with the default values, which is recommended for most.

Once finished we can configure our current shell to start working:

source $HOME/.cargo/env 

And we can start using it. For example, if you want to see the version you just installed and check that everything is OK:

rustc --version 

If you have Rust installed and you want to update to the new version, you just have to type:

rustup update stable 

Leave a Comment

Your email address will not be published. Required fields are marked with *

*

*

  1. Responsible for the data: AB Internet Networks 2008 SL
  2. Purpose of the data: Control SPAM, comment management.
  3. Legitimation: Your consent
  4. Communication of the data: The data will not be communicated to third parties except by legal obligation.
  5. Data storage: Database hosted by Occentus Networks (EU)
  6. Rights: At any time you can limit, recover and delete your information.