📜 ⬆️ ⬇️

"Curse" braces

Suppose you are a large company. Engaged in the development of browser, mailer and even OS for smartphones. Suddenly, you realize that you do not like the modern and powerful C ++ language. Well, or like, but it is impossible to work with him. It happens. And here you, the adult stable company decide to develop a new programming language. The recipe is simple. Take a barrel of money, books on the history of IT, a company of programmers and a truck MacBook. Long think, quickly code, make HYIP on social networks (reddit, facebook, github). And so, in 2015, you give the community The Language. Let's call it Yaist.

Language is a tool for professionals. Working by profession means professional. What is the first thing a professional reads when learning a new language? Of course, the objective opinion of colleagues. It is mostly positive. Following the opinion of colleagues, the professional reads the language description . More than two hundred pages. Oh. Will than kill time in the subway.

Fast start


Hello, World!


The most important stage of the study.

fn main() {
  println!("Hello, world!");
}

? fn, , , println!. , . .

, fn. PROCEDURE, , Shift . , . main() . . void, . void . - .
. , , 70-. . BEGIN END, 21- . .

println! . . , , . , , ( , std). , println! 90- Log.String(«Hello, World!»). , .

. expression based . . . 90- END Main. , .

Cargo


. , . . 90- . . . Cargo toml — ini .


.

use std::io;
fn main() {
  println!("Guess the number!");
  println!("Please input your guess.");
  let mut guess = String::new();
  io::stdin().read_line(&mut guess)
    .ok()
    .expect("Failed to read line");
  println!("You guessed: {}", guess);
}


, io std. Use std::io, Luke; , . , IMPORT StdIO, . . . , #. println! .

, . , , . , . . . , .

. . .

String . new() new(). io::stdin() println! .

.

extern crate rand;


, , use , . , , . , , . . .

match guess.cmp(&secret_number) {
  Ordering::Less => println!("Too small!"),
  Ordering::Greater => println!("Too big!"),
  Ordering::Equal => println!("You win!"),
}


cmp() . Enum' c match. CASE, . . -. => , .

. break continue, . , , . . 90- , , . , .


Philosophers eat(). . , , &self ( this). 90- , 2015 . new, . .

vec!. . .
.

let handles: Vec<_> = philosophers.into_iter().map(|p| {
  thread::spawn(move || {
    p.eat();
  })
}).collect();


, . . . , . , . . . 90- . . , . .

use std::sync::{Mutex, Arc};


.


— shared library.

, shared libraries Windows/Linux . , , (, , ), C. . . 2015- , dll , . , FFI. , - . , , — . , shared library.

#[no_mangle]
pub extern fn process() 


Shared Library .




, . , , , . . , . . , . , - .


, , . , , .


. assert! . , .


. . , 2015- .

, , , , , /, , .


. HTML. .


, , , . - . 2015- . .


, , , , /. -.

FFI


- - . , . FFI, .

Borrow and AsRef traits


Trait , . - . , , . , , .

l4ngu4g3 6oN



5 . , . :
, , , scope, heap (- ), , , , .

, , ( ) . , , . , . , .


, . , . , - . .

, , , . , , , «» .

, , . , , . , , .

, . , , . , . , , , .

, , , . .

«» . . . .

')

Source: https://habr.com/ru/post/258391/


All Articles