rust 编程入门_面向初学者的Rust –最受欢迎的编程语言入门

rust 编程入门

Rust has been voted Stack Overflow’s most loved programming language for five years in a row. This article will tell you why Rust is awesome.

Rust已连续五年被评为Stack Overflow最受欢迎的编程语言。 本文将告诉您为什么Rust很棒。

Rust is a systems programming language that you can use to write applications with high performance. Rust is used by some of the top tech companies like Dropbox and Cloudflare to deliver speed and concurrency to their customers.

Rust是一种系统编程语言 ,可用于编写高性能的应用程序。 一些顶级高科技公司(例如Dropbox和Cloudflare)使用Rust来为其客户提供速度和并发性。

For the last five years in a row, Rust has been voted as the most loved programming language.

在过去的五年中,Rust被评选为最受欢迎的编程语言。

But chances are, you might not have worked with Rust. Or worse, you might not have heard of it before. So let's learn more about it.

但是有可能,您可能没有使用Rust。 或更糟糕的是,您可能以前从未听说过它。 因此,让我们进一步了解它。

为什么生锈? (Why Rust?)

Let’s look at why a developer would choose Rust.

让我们看看为什么开发人员会选择Rust。

Typical programming languages like Python and C++ abstract a lot of details away from developers.

诸如Python和C ++之类的典型编程语言从开发人员那里提取了许多细节。

If you are a junior developer working on a simple web application, this might not an issue. You just want to find a solution to a problem.

如果您是从事简单Web应用程序的初级开发人员,那么这可能不是问题。 您只想找到问题的解决方案。

For large scale applications that millions of users will use on a daily basis, the ‘problem-solving’ approach will not work. More users consume more system resources. And more resources mean bigger bills for your company.

对于每天将有数百万用户使用的大规模应用程序,“问题解决”方法将行不通。 更多的用户消耗更多的系统资源。 更多的资源意味着您公司的账单更大。

This is where Rust shines. Rust combines ease of programming with access to core system configurations. Rust is built with memory-safety, concurrency, and security from the ground up.

这是Rust发光的地方。 Rust将易于编程与对核心系统配置的访问结合在一起。 Rust从一开始就具有内存安全性,并发性和安全性。

Rust is a “systems programming language that focuses on speed, memory safety, and parallelism”.
Rust是一种“专注于速度,内存安全和并行性的系统编程语言”。

Rust is also considered to be a great alternative for C++. Rust offers high performance in addition to helping you eliminate common bugs caused by languages like C++.

Rust也被认为是C ++的绝佳替代品。 除帮助您消除由C ++之类的语言引起的常见错误外,Rust还提供了高性能

Now that you know what Rust can do for you, let's look at Rust in detail.

既然您知道Rust可以为您做什么,那么让我们详细了解Rust。

起源 ( Origins)

Rust is an open-source programming language. It was first introduced to the world in 2010 by Graydon Hoare, while he was working at Mozilla. Shortly after, Mozilla began sponsoring this project and is still a core contributor to Rust.

Rust是一种开源编程语言。 Graydon Hoare在Mozilla工作时于2010年首次将其引入世界。 此后不久,Mozilla开始赞助该项目,并且仍然是Rust的核心贡献者。

Rust started gaining popularity over the years. Even Microsoft uses Rust to build secure and safety-critical software components.

多年来,Rust开始流行。 甚至Microsoft都使用Rust来构建安全且对安全性至关重要的软件组件。

核心功能 ( Core Features)

Let's look at some core features that make Rust stand out from other programming languages.

让我们看一些使Rust在其他编程语言中脱颖而出的核心功能。

性能 (Performance)

Rust was built to be high performance form the ground up. Rust offers fine-grained control of memory management and has a minimal standard library.

Rust被构建为具有高性能的基础。 Rust提供了对内存管理的细粒度控制,并且具有最小的标准库。

If you look at some of the metrics shared by Figma, they had incredible improvements in performance once they switched to Rust.

如果您看一下Figma共享的一些指标 ,当他们切换到Rust时,它们在性能上有了惊人的提高。

Rust’s low memory footprint also makes it an ideal choice for embedded systems programming. You can use Rust to write software for IoT devices like home automation hubs, smart security systems, and so on.

Rust的低内存占用空间也使其成为嵌入式系统编程的理想选择。 您可以使用Rust来为IoT设备(例如家庭自动化集线器,智能安全系统等)编写软件。

安全 (Security)

One of the major reasons Microsoft decided to root for Rust is its security.

微软决定支持Rust的主要原因之一是其安全性。

The majority of vulnerabilities in Microsoft software were due to poor memory management in C & C++. This lead to simple yet powerful exploits like the Buffer Overflow exploit that had crippled Windows for years.

Microsoft软件中的大多数漏洞是由于C&C ++中的内存管理不良所致。 这导致了简单而强大的漏洞利用 ,例如使Windows瘫痪多年的“ 缓冲区溢出”漏洞

So Microsoft decided to look for the best alternative to C++. And they found Rust.

因此,Microsoft决定寻找C ++的最佳替代品。 他们发现了Rust。

Using Rust eliminates an entire class of security vulnerabilities from software applications. This helps companies build applications with better performance and higher security.

使用Rust消除了软件应用程序中的一整类安全漏洞。 这有助于公司构建具有更好性能和更高安全性的应用程序。

并发 (Concurrency)

Concurrency is when two or more tasks start, run, and complete in overlapping time. Database operations are a great example to explain concurrency.

并发是指两个或多个任务在重叠时间内启动,运行和完成。 数据库操作是解释并发性的一个很好的例子。

When thousands of users are using your application at the same time to perform different actions, your database handles them concurrently. Concurrency is a key concept when it comes to scaling applications.

当成千上万的用户同时使用您的应用程序执行不同的操作时,数据库将同时处理它们。 当扩展应用程序时,并发是一个关键概念。

Concurrency and parallelism are also built into Rust. Rust solves most of the concurrency problems during compile time by using the concept of Ownerships. Learn how Rust handles concurrency here.

并发和并行性也内置在Rust中。 Rust使用所有权概念解决了编译期间的大多数并发问题。 在此处了解Rust如何处理并发

使用Rust (Working With Rust)

Now that you understand the core features of Rust, let's write a few lines of code. You can find installation instructions here if you want to try out Rust on your computer.

现在您了解了Rust的核心功能,让我们写几行代码。 如果要在计算机上试用Rust,可以在这里找到安装说明

Let's start with a simple “Hello World!” function.

让我们从一个简单的“ Hello World!”开始。 功能。

// Main function
fn main() {
	println!("Hello World!");
}

Yep. That's pretty much it. Let's try to add two numbers.

是的 就是这样。 让我们尝试将两个数字相加。

// Main function
fn main() {
	let a = 100;
    let b = 200;
    println!("Result is {}",a+b);
}

Again, pretty standard. Now let's look at an array operation.

再次,相当标准。 现在让我们看一下数组操作。

// Main function
fn main(){
	let arr:[i32;4] = [1,2,3,4];
    println!("array size is {}",arr.len());
}

If you look at line 3, we use “:[i32;4]”. Here we tell Rust that we are declaring an array of length 4 with 32-bit integers.

如果您看一下第3行,我们使用“:[i32; 4]”。 在这里,我们告诉Rust,我们正在声明一个长度为4的数组,其中包含32位整数。

Declaring data types in detail is a key factor in improving the performance of a program. You are helping the compiler save time by explicitly declaring what type of data you are about to assign to a variable.

详细声明数据类型是提高程序性能的关键因素。 您通过明确声明将要分配给变量的数据类型来帮助编译器节省时间。

Letting the compiler figure out the data type is one of the main reasons you run into performance issues while scaling your application.

让编译器弄清楚数据类型是在扩展应用程序时遇到性能问题的主要原因之一。

Also, Rust is a statically typed language, which means it must know the types of all variables at compile time.

同样, Rust是一种静态类型的语言 ,这意味着它必须在编译时知道所有变量的类型。

Though Rust is syntactically similar to C and C++, don't let its simplicity fool you. Rust does come with a steep learning curve. But it is totally worth it once you get a good grasp of the basics.

尽管Rust在语法上类似于C和C ++,但不要让其简单性欺骗您。 Rust确实具有陡峭的学习曲线。 但是,一旦您掌握了基本知识,就完全值得。

谁使用Rust? (Who Uses Rust?)

Now that you have a good grasp of what Rust is, let's look at who uses Rust.

既然您已经了解了Rust是什么,那么让我们看看谁使用Rust。

微软 (Microsoft)

Once a fierce adversary of open source, Microsoft is now an avid contributor to a number of open-source projects. Their .net core project is one of the most popular open-source frameworks used by developers today.

曾经是开源的激烈对手,Microsoft现在是许多开源项目的热心贡献者。 他们的.net核心项目是当今开发人员使用的最受欢迎的开源框架之一。

Microsoft has chosen Rust for security and performance-critical applications. Rust is also used extensively in Azure, especially in its IoT Edge platform to run AI applications on IoT devices.

Microsoft已选择Rust用于安全性和对性能至关重要的应用程序。 Rust在Azure中也被广泛使用,尤其是在其IoT Edge平台中,以在IoT设备上运行AI应用程序。

投寄箱 (Dropbox)

Dropbox uses Rust to improve its data center efficiency. Rust is now powering core services of Dropbox serving more than 500 million users.

Dropbox使用Rust来提高其数据中心效率。 Rust现在为Dropbox的核心服务提供支持,为超过5亿用户提供服务。

Dropbox recently wrote a detailed article on how they re-wrote their core engine.

Dropbox 最近写了一篇有关如何重新编写其核心引擎的详细文章

In Dropbox’s own words,

用Dropbox自己的话说,

Rust has been a force multiplier for our team, and betting on Rust was one of the best decisions we made.
Rust一直是我们团队的力量倍增器,对Rust的押注是我们做出的最佳决定之一。

Rust was also a contributing factor that helped Dropbox move its infrastructure from AWS to its own data centers.

Rust也是帮助Dropbox将其基础架构从AWS迁移到其自己的数据中心的一个促成因素。

菲格玛 (Figma)



Figma is a cloud-based designing and prototyping tool that you can use in your browser. It is an excellent tool for designing, prototyping, and exporting your designs into code. Learn more about Figma here.

Figma是一种基于云的设计和原型制作工具,可以在浏览器中使用。 它是用于设计,制作原型并将设计导出到代码中的出色工具。 在此处了解有关Figma的更多信息

Concurrency is crucial for a collaborative tool where many users will be working on a single design at a time. Figma used Rust to write a high-performance server that helped them scale their product and achieve the performance they were looking for.

并发对于一个协作工具至关重要,在协作工具中,许多用户将同时处理一个设计。 Figma使用Rust编写了一个高性能服务器,可以帮助他们扩展产品并实现他们想要的性能。

Here is the article Figma wrote about their experience with Rust.

这是Figma写的关于他们在Rust方面的经验的文章

TL; DR (TL;DR)

Rust is a systems programming language that has been voted as StackOverflow’s most loved programming languages, four years in a row.

Rust是一种系统编程语言,已连续四年被评为StackOverflow最受欢迎的编程语言

Rust gives you control over low-level details and provides remarkable improvements in speed and stability.

Rust使您可以控制低级细节,并在速度和稳定性方面取得了显着改善。

It has helped companies like Dropbox, Figma, and Microsoft build better applications for their customers.

它已经帮助Dropbox,Figma和Microsoft等公司为其客户构建更好的应用程序。

The language is being increasingly adopted by companies looking to scale their applications with higher performance and concurrency. Sounds interesting? Start learning Rust here.

希望通过更高性能和并发性扩展其应用程序的公司越来越多地采用该语言。 听起来不错? 从这里开始学习Rust



I regularly write about Machine Learning, Cyber Security, and DevOps. You can signup for my weekly newsletter here.

我定期撰写有关机器学习,网络安全和DevOps的文章。 您可以 在这里 注册我的 每周新闻

翻译自: https://www.freecodecamp.org/news/rust-getting-started-with-the-most-loved-programming-language/

rust 编程入门

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值