DEV Community

Cover image for Rust Implementation Guide - from efficient learning to implementation
Satoshi Konno
Satoshi Konno

Posted on

Rust Implementation Guide - from efficient learning to implementation

In the last issue [30], I implemented the same application in Go, Rust, and C (+ Python) and evaluated the implementation efficiency and speed with each language. In this article, we will summarize our views on how to learn and implement Rust efficiently based on our experience.

How to learn Rust

Rust is considered a language that requires a learning period before productivity is realized [5]. With statistics showing that more than 50% of people leave during the initial learning phase and many of them fail within a month [6], effective initial learning is especially important.

STEP1: Overcoming the Learning Readiness Phase

There are many esoteric interpretations of the Rust compiler (without explicit solutions) [11], but first learn the basics of the Rust compiler until you understand and can interact with its error content.

While Rust is rife with books and materials for beginners [5], there is a dearth of materials aimed at practical intermediate and above [5] has not improved much. In conclusion, instead of struggling with compilers in the dark, the shortcut to Rust mastery is to first improve basic skills with good learning materials, which are the primary resources shown below [7][8].

There are also scattered opinions that C/C++ is easy for skilled users to learn [7][9][10], so in terms of deepening the usefulness of Rust, it is also important to deepen the C/C ++ language may also be a shortcut to learning Rust.

STEP2: Practical project challenges

If your goal is to "learn Rust," you will have achieved your objective at this stage. However, the difficulty of Rust lies in the difficulty of practice, after overcoming the preparatory phase of the learning curve [5][11][12][15]. In conclusion, it seems to be efficient for Rust learning to start some kind of practical project [13][14].

If it does not follow the semantics of Rust, design patterns (experience) in other programming languages cannot be brought in directly [16], and trial and error is required. In terms of comparison with existing languages, the following tutorials may be helpful.

As mentioned above, the situation [5], where there is a dearth of material aimed at the practical intermediate level and above, has not improved very much. As an actual example, you can read the divergence between the following materials recommended for beginners to step up and the practical subject matter [15] shown in the above tutorial.

In other words, because there is not as much "Effective" intermediate and above information as in other languages, you need to struggle with the Rust compiler and establish (pioneer) the following design patterns (experiences) [16] must be established (pioneered) by yourself while struggling with the Rust compiler.

Many books and materials that are considered intermediate level are simplified by limiting the field of application, both in a good and bad way. In conclusion, there are few things better than official materials, and a practical shortcut may be to deepen understanding by trial and error while going back to official materials in practice.

Books that are field-specific in title are an effective way to gain implementation knowledge of Rust in a specific area, serving as a Rosetta Stone of sorts. However, it should be understood only as one implementation example, and whether it is the best way or not may be reconsidered through practice.

Rust at Work

The most recent Rust community survey included a "Rust at Work" item [21][13], which emphasizes the adoption of Rut as a professional language. The most recent, 2021 survey results [13] show that while the rate of use at work has increased significantly from 42% to 59% in the previous year, industry adoption The lack of adoption in the industry was cited as the biggest concern (38%) for Rust's future.

Basically, a programming language is a means to an end and should be selected based on the circumstances of the target project and team. Based on this assumption, here is a list of items to consider when adopting Rust.

Consideration of project characteristics

First, it is important to determine whether the project to which Rust is applied is compatible with Rust semantics, in the sense of avoiding implementation complexity and performance degradation in Rust. Simply put, a project that is not stateless and involves parallel processing with data sharing in the Rust processing unit cannot be handled solely with Rust's move (Move) semantics, and ownership and lifetime management will become more complex.

For example, stateless web applications and[31], which can be handled naturally with Rust's move (Move) semantics and SEDA[32], which are concurrency models that do not require data sharing, the semantics of Rust adoption is unlikely to be a problem.

Also, if we ignore the compatibility and complexity of the implementation, the adoption track record of Rust in the same field as the project, and for what applications and at what scale it has been implemented, will be a good guide for making an adoption decision [14].

Secure core members

What is clear is that if you are at a stage where you do not have personnel proficient in Rust, and you cannot determine the compatibility of Rust with the characteristics of your project, you should avoid hiring Rust. Simply put, you should avoid hiring Rust out of curiosity.

It is essential to have a core team that is proficient in Rust. Conversely, if the core team has established design patterns for Rust implementation, it will be easier to add more people to the project, even if they are new to Rust.

Basically, if core members have established a template or methodology for implementing Rust in a project, new members can follow that style and extend the project structure even if they are not necessarily proficient in Rust.

Scope of Standard Library Offerings

Rust is a language that has strengths in system programming and situations where high performance is required, but the coverage and functionality of the standard library is on the poor side, similar to the C language. The standard library provided lacks functionality and speed [30]. memo/rust-eval-loc-perf/)[30][31], and other maturity challenges In some cases, the

Realistically, considering the scope of standard library offerings and the economics of the project, we will have to take the approach of developing a combination of third-party crates. In particular, for complex data structures and highly parallel processing functions, we are forced to rely heavily on third-party crates.

However, depending on the quality and maintenance status of the crate, the project may be more at risk, and this should be taken into consideration. Also, as with Perl's CPAN, crates are registered on a first-come, first-served basis, so even if a crate is published under a major name, there may be alternative crates of higher quality and more actively developed, so thorough investigation is essential before adoption.

Inheritance of past assets

Realistically, many will want to leverage existing development assets rather than implement exclusively in Rust, and Rust continues to see a high demand for interoperability with C/C++ language assets as an important issue [5][24][25][26][27][28][29].

Compared to C++, Objective-C, and Go, where interoperability with C is guaranteed at the language level and can be used simply by including header files, Rust's interoperability is one major barrier. Rust provides a FFI (Foreign Function Interface) to interface with other languages, but interoperation with C requires a separate FFI definition that shows the correspondence with Rust types. rust-bindgen[27], but there are also FFI generators such as [28][29] will be an important factor in the decision to adopt Rust.

Conclusion

While Rust is highly secure and performs well, learning Rust involves steep hurdles and struggles with the compiler, so effective learning methods and preparation are necessary. In the initial stages, it is important to cultivate a basic ability to understand and respond to compiler error messages, and to ensure that you learn Rust-specific concepts by using good official materials and books for beginning students.

When considering the adoption of Rust for a project, it is particularly important to confirm the project characteristics and the Rust proficiency of the team, and to establish appropriate design patterns and support systems.

We hope that by utilizing the learning materials and reference materials introduced in this article, you will be able to maximize the potential of Rust by establishing basic skills and then putting them into practice.

Top comments (0)