176x Filetype PDF File size 1.93 MB Source: www.tutorialspoint.com
RUST i RUST About the Tutorial Rust is a modern systems programming language developed by the Mozilla Corporation. It is intended to be a language for highly concurrent and highly secure systems. It compiles to native code; hence, it is blazingly fast like C and C++. This tutorial adopts a simple and practical approach to describe the concepts of Rust programming. Audience This tutorial has been prepared for beginners to help them understand the basic and advanced concepts of Rust. Prerequisites We assume that the reader has an understanding of basic programming concepts is necessary for this course. Copyright & Disclaimer Copyright 2019 by Tutorials Point (I) Pvt. Ltd. All the content and graphics published in this e-book are the property of Tutorials Point (I) Pvt. Ltd. The user of this e-book is prohibited to reuse, retain, copy, distribute or republish any contents or a part of contents of this e-book in any manner without written consent of the publisher. We strive to update the contents of our website and tutorials as timely and as precisely as possible, however, the contents may contain inaccuracies or errors. Tutorials Point (I) Pvt. Ltd. provides no guarantee regarding the accuracy, timeliness or completeness of our website or its contents including this tutorial. If you discover any errors on our website or in this tutorial, please notify us at contact@tutorialspoint.com i RUST Table of Contents About the Tutorial ...................................................................................................................................... i Audience .................................................................................................................................................... i Prerequisites .............................................................................................................................................. i Copyright & Disclaimer ............................................................................................................................... i Table of Contents ...................................................................................................................................... ii 1. RUST — Introduction ................................................................................................................................ 1 Application v/s Systems Programming Languages ...................................................................................... 1 Why Rust? ................................................................................................................................................. 1 2. RUST — Environment Setup ...................................................................................................................... 3 Installation on Windows ............................................................................................................................ 3 Installation on Linux / Mac ......................................................................................................................... 5 Using Tutorials Point Coding Ground for RUST ........................................................................................... 5 3. RUST — HelloWorld Example .................................................................................................................... 6 What is a macro? ....................................................................................................................................... 7 4. RUST — Data Types ................................................................................................................................... 9 Declare a Variable...................................................................................................................................... 9 Scalar Types............................................................................................................................................. 10 Integer .................................................................................................................................................... 10 Float ........................................................................................................................................................ 12 Boolean ................................................................................................................................................... 13 Character ................................................................................................................................................ 14 5. RUST — Variables ................................................................................................................................... 15 Rules for Naming a Variable ..................................................................................................................... 15 Syntax ..................................................................................................................................................... 15 Immutable ............................................................................................................................................... 15 Mutable .................................................................................................................................................. 16 ii RUST 6. RUST — Constant .................................................................................................................................... 18 Rust Constant Naming Convention ........................................................................................................... 18 Constants v/s Variables............................................................................................................................ 18 Shadowing of Variables and Constants ..................................................................................................... 19 7. RUST — String ......................................................................................................................................... 21 String Literal ............................................................................................................................................ 21 String Object ........................................................................................................................................... 22 Illustration: new() .................................................................................................................................... 24 Illustration: to_string() ............................................................................................................................. 24 Illustration: replace() ............................................................................................................................... 24 Illustration: as_str() ................................................................................................................................. 25 Illustration: push() ................................................................................................................................... 25 Illustration: push_str() ............................................................................................................................. 26 Illustration: len() ...................................................................................................................................... 26 Illustration: trim() .................................................................................................................................... 26 Illustration:split_whitespace() .................................................................................................................. 27 Illustration: split() string........................................................................................................................... 28 Illustration: chars() .................................................................................................................................. 28 Concatenation of Strings with + operator ................................................................................................. 29 Illustration: Type Casting ......................................................................................................................... 30 Illustration: Format! Macro ...................................................................................................................... 30 8. RUST — Operators .................................................................................................................................. 31 Arithmetic Operators ............................................................................................................................... 31 Relational Operators................................................................................................................................ 32 Logical Operators .................................................................................................................................... 34 Bitwise Operators .................................................................................................................................... 35 9. RUST — Decision Making ........................................................................................................................ 38 If Statement ............................................................................................................................................ 39 iii
no reviews yet
Please Login to review.