Skip to content

annguyen200011/CS308_Rust

Repository files navigation

History-and-Hello-World: Rust

image

Table of content

Overview

Name: Rust

History

First appearing in 2010, Rust was designed by Graydon Hoare at Mozilla Research, with contributions from Dave Herman, Brendan Eich, and others.

Rust is a multi-paradigm, general-purpose programming language designed for performance and safety, especially safe concurrency. Rust is syntactically similar to C++, but can guarantee memory safety. Rust has been called a systems programming language and in addition to high-level features such as functional programming it also offers mechanisms for low-level memory management.

Why Rust?

  • Performance: Rust is blazingly fast and memory-efficient: with no runtime or garbage collector, it can power performance-critical services, run on embedded devices, and easily integrate with other languages.
  • Reliability: Rust’s rich type system and ownership model guarantee memory-safety and thread-safety — enabling you to eliminate many classes of bugs at compile-time.
  • Productivity: Rust has great documentation, a friendly compiler with useful error messages, and top-notch tooling — an integrated package manager and build tool, smart multi-editor support with auto-completion and type inspections, an auto-formatter, and more.

Rust is used for?

Rust has been adopted by major software engineering companies. Rust is used for:

  • Web browsers and services: Firefox, OpenDNS, Deno, Figma,...
  • Operating systems: Redox, Theseus, Google Fuchia, Stratis,...
  • Other notable projects and platforms: Discord, Microsoft Azure, Amazon Web Services, Polkadot (cryptocurrency),...

Note: What I like most about rust programming language is its popularity in Dapps(Decentralize Applications) programming. I plan to program blockchain applications.

Learning sources

Next reading

  1. Names, Types and Binding
  2. Selection Control Structures
  3. Loops and Subroutines
  4. Objects and Classes

Setup

Main tool

  1. rustc: The complier which takes your Rust code and compiles it into binary (machine readable code)
  2. rustup: The command line utility to install and update Rust
  3. cargo: The Rust build system and package manager

How to install?

  1. Install Programing Enviroment: Visual Studio C++ Build tools
  2. Install Rust
  3. Install Intellij IDEA and Intellij Rust Plugin

Run program in Intellij IDEA

  1. Create new project: Go to File | New | Project (File | New Project) or click New project on the welcome screen.

  2. Select Rust from the list in the left-hand pane.

  3. Choose the template to used, specify the project name, location, and toolchain parameters: image

  4. Click Create when ready, and the IDE will generate a ready-to-go stub project: image

Comments

Non-doc comments

Comments in Rust code follow the general C++ style of line (//) and block (/* ... */) comment forms. Nested block comments are supported.

Non-doc comments are interpreted as a form of whitespace.

Doc comments

Line doc comments beginning with exactly three slashes (///), and block doc comments (/** ... */), both inner doc comments, are interpreted as a special syntax for doc attributes. That is, they are equivalent to writing #[doc="..."] around the body of the comment, i.e., /// Foo turns into #[doc="Foo"] and /** Bar */ turns into #[doc="Bar"].

Line comments beginning with //! and block comments /*! ... */ are doc comments that apply to the parent of the comment, rather than the item that follows. That is, they are equivalent to writing #![doc="..."] around the body of the comment. //! comments are usually used to document modules that occupy a source file.

Isolated CRs (\r), i.e. not followed by LF (\n), are not allowed in doc comments.

Examples

#![allow(unused_variables)]
fn main() {
//! A doc comment that applies to the implicit anonymous module of this crate

pub mod outer_module {

    //!  - Inner line doc
    //!! - Still an inner line doc (but with a bang at the beginning)

    /*!  - Inner block doc */
    /*!! - Still an inner block doc (but with a bang at the beginning) */

    //   - Only a comment
    ///  - Outer line doc (exactly 3 slashes)
    //// - Only a comment

    /*   - Only a comment */
    /**  - Outer block doc (exactly) 2 asterisks */
    /*** - Only a comment */

    pub mod inner_module {}

    pub mod nested_comments {
        /* In Rust /* we can /* nest comments */ */ */

        // All three types of block comments can contain or be nested inside
        // any other type:

        /*   /* */  /** */  /*! */  */
        /*!  /* */  /** */  /*! */  */
        /**  /* */  /** */  /*! */  */
        pub mod dummy_item {}
    }

    pub mod degenerate_cases {
        // empty inner line doc
        //!
    
        // empty inner block doc
        /*!*/

        // empty line comment
        //
        
        // empty outer line doc
        ///
        
        // empty block comment
        /**/

        pub mod dummy_item {}

        // empty 2-asterisk block isn't a doc block, it is a block comment
        /***/

    }

    /* The next one isn't allowed because outer doc comments
       require an item that will receive the doc */

    /// Where is my item?
  mod boo {}
}

Reference

  1. https://en.wikipedia.org/wiki/Rust_(programming_language)
  2. https://www.rust-lang.org/
  3. https://www.rust-lang.org/tools/install
  4. https://plugins.jetbrains.com/plugin/8182-rust/docs/rust-quick-start.html
  5. https://doc.rust-lang.org/reference/comments.html
  6. https://www.youtube.com/watch?v=NufU_fRpStA

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published