Using Rust Playground for Hello World and Variable Interpolation
source link: https://fuzzyblog.io/blog/rust/2020/03/02/using-rust-playground-for-hello-world-and-variable-interpolation.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Using Rust Playground for Hello World and Variable Interpolation
Mar 2, 2020
Artwork by my friend Autumn Mott; Hopefully I can find a better link to put here
It is a Monday and what better way to start your 6 am Monday morning then learning some of the elements of a new language – Rust.
I started by adding a link in my Browser toolbar to the Rust Playground which amounts to a web based REPL (Read Evaluate Print Loop) for Rust where you can type in Rust code and run it. Yes I know it really isn't a REPL because Rust is a compiled language not an interpreted one but it functions well enough as a REPL that I can wrap my Ruby tinged mind around it.
Here's the Hello World program that automatically appears in the Rust playground
fn main() {
println!("Hello, world!");
}
The output of this is:
Hello, world!
That's pretty easy to understand:
- A main function defined with fn
- A print line function defined with a ! (my previous Rust reading tells me that's a macro indicator)
- { and } to denote structure
- A ; to denote the end of lines
I wanted to make a simple change to experiment with the use of variables so I added a main2() function and called it from main():
fn main() {
println!("Hello, world!");
main2();
}
fn main2() {
let x = 5;
println!("The value of x is: {}", x);
let y = 6;
println!("The value of y is: {}", y);
}
The output of this is:
Hello, world!
The value of x is: 5
The value of y is: 6
You can see that the let keyword assigns a variable and that {} binds a variable into a string (which is generally called interpolation).
Note: Variables quickly bring you in to the heart of Rust – immutability – and here there by dragons that hopefully come up tomorrow after some reading.
Here's a permanent link to this if you want to try it out.
What about Repl.it?
Another way to have a web based REPL for Rust is Repl.it. And while I like the concept of repl.it, they have eliminated any privacy without a paid account: Upgrade your account for private repls. This appears on the bottom of every new REPL you create and at $74 / 12 months that feels expensive simply for the basics of privacy.
Posted In: #rust #variables
Recommend
-
11
Note 本文摘录自《Go语言趣学指南》第 1 章, 请访问 gpwgcn.com 以获取更多相关信息。
-
12
最近在和我一同事一起,使用 Rust 来创造一门新的编程语言: Charj 。而在实践方面,我们都是这方面的新手,所以不得不经历一番尝试。而作为其中的一部分,必然就是由一个 hello, wor...
-
10
Go Playground 与 Hello World¶ 本文摘录自《Go语言趣学指南》第 1 章, 请访问 gpwgcn.com 以获取更多相关...
-
7
Rust + LLVM + JIT hello, world 示例 Posted by: Phodal Huang Nov. 22, 2020, 3:01 p.m. 最近在和我一同事一起,使用 Rust 来创造一门新的编程语言:
-
13
The following is an excerpt from my book, Rails Testing for Beginners. What we’re going to do One of the biggest challenges in getting started with testin...
-
28
ADFv2 Variable String Interpolation – REST API Body As we know Azure Data Factory (ADF) Version 2 now has the ability to use expressions, parameters and system variables in various components throughout the service....
-
5
Rust Playground At Your Fingertips 2021-03-12 Coming to Rust from Ruby I miss the interactive console (IRB) lot. Sometimes I go to Rust Plyaground online to test simple things, but...
-
3
故事是這樣子的,很早之前寫了 Rust/Amethyst 系列文, 最後把這個系列文拿去投稿了 2020 年的 MOPCON, 在投稿的時候,為了跟以網路為主題的...
-
7
0:00 / 16:15 ...
-
3
What’s New in C# 10: Create Constants Using String Interpolation This is part of a series on the new features introduced with C# 10.Prior to C# 10 if you wanted to...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK