Some features of the rust language (expression-based system programming language?) )

Source: Internet
Author: User

1, letmut x = 10i; In academic terms, let represents the grammar-level name binding (to the Value object)

println! is a macro, the first time I saw it, I thought it was learning ruby,!. The representative function has side effects.

Destructuring let: The concept of deconstructed bindings comes from Lisp/erlang?


2. Expression language: If is an expression, plus a semicolon becomes a statement;return x; is equivalent to a direct X

Also, it's if/for/while condition to not add () parentheses, which is consistent with Swift (it feels a bit awkward)


3. Function prototype: FN f (x:int, Y: &str), () {...}

The grammatical style used here is similar to that of C + + 11 and Scala.


4, string is a utf-8 encoded Unicode character sequence (k, incredibly forced encoding)

String.as_slice () = = "Hello" compares string = = "Hello". To_string () The concept here is a bit weird and needs to be thought over (what does the language designer want to say?). )


5, Tuple,struct,tuple struct--the distinction between the 3 is quite interesting, the concept of a Tuple should be from the python? Corresponding to the pair template in C + + STL


6. Vector (Array)

Let nums = [1i,.. 20]; Shorthand for a array of elements all initialized to 1


7. Standard input:

 Let input = std::io::stdin(). Read_line (). OK (). expect ("Failed to read line"); Ioresult<t>?

8. Cargo the configuration file suffix of the Package Manager. TOML is not good, it feels a little weird


9, rand::random::<int> (); Hell, the syntax for instantiating a function template is weird, too.
Does the author have any intention to design language???


10, Crates (independent compilation unit?) ) and Module

MoD Hello {    pubfnPrint_hello() {        println! ("Hello, world!");}    }
By


11. Integrated unit test support?

#[Test]

Why do you have to add a # to the attribute label here? To prevent the misunderstanding of grammatical parsing as vector? But # has been used as a line comment in many scripting languages, this is not a good design


12. Pointers

(1) References: let y = &x; Literal constants can be referenced directly

 Let Mut x = 5i;  Let y = & Mut x;

(2) Ownership relationship, borrowing and life cycle

(3) Boxing (the primitive is encapsulated as a heap object?) )
(4) RC and Arc: (automatic) reference count, cannot have circular reference!


13. Pattern Matching

 Let Mut x = 5i;Match x{ref Mut x = println!("Got a mutable reference to {}",x),}
14. Closed Package

 Let Add_one = | x | 1i + x };
15, Proc (this concept should be from Ruby, but now coroutine so popular, proc probably outdated? )

16. iterators

 for Num inch nums. ITER () { ... }
Do you have to add a. iter ()?

17, the consumer (slightly)

18, re-study Scala/c#/haskell:

 Let x Option < int > = Some (5i);

19, Traits (temporary)

20. Task tasks: This place is a fight with python/go and so on .

21. Unsafe (~c#): Used to connect with external numerical calculation module?


Source: http://doc.rust-lang.org/guide.html


Some features of the rust language (expression-based system programming language?) )

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.