    Rust
 


  -     Rust  ,      , ,   ,   ,    ,   .

    -   .            .





 

    Rust





 I.  





 1.    


1.1.  

  - ,     ,    .  -   :   ,        ,   .  -   ,        ;    .  -   ,   ,      .   -    ,  ;        .  - ,      ,     ,   .   -   ; ,     .

1.2.   

   ,  .      . ,        .   . ,    ,  .

 1.1.    .

fn main() {

println!(" :  .");

}

 fn main()     main.  -   ;  fn     ,  .     : ,    .        -  println!.   ,  println!  ,   ,        ;        .

 1.2.   .

      main.rs.  rustc main.rs  ;        main.  ./main   .      " :  .".

 " "  :   -   ,     ;      ,    ,     .

 

   ?

         ?

     rustc main.rs?

   ,       Rust?

      println!?



 ,   .    .

    1.1 ,         println!.

     ,   main.rs,   .      .

 ,    ,        ,       (, "2 + 2 = 4" -  4  ,  ).

  print_greeting,    -    -   ,   .        ; ,    5 ,     ,     .




 2.     


2.1.  

  -     ,    . ,    ,     .   -      ;  ,    .   -  ,      ;   .   -    .     -  ,    ,   .     -  ,    .   - ,     ,   ;       .   -     :   .  -   ,   ,    .

2.2.  

    :     .        . i8       ; i16, i32, i64 - ,     . u8, u16, u32, u64 -    .  i    ""   ,  u -   "".

 2.1.    .

fn main() {

let temperature: i32 = -12;

let population: u64 = 1_400_000;

let flag_byte: u8 = 255;

println!("temperature = {}", temperature);

println!("population = {}", population);

println!("flag_byte = {}", flag_byte);

}

 let    .          ;         .  1_400_000  1400000      ;               .  {}     ,     .

 2.2.  .

fn main() {

println!("i8  : {} ", std::mem::size_of::<i8>());

println!("i32 : {} ", std::mem::size_of::<i32>());

println!("u64 : {} ", std::mem::size_of::<u64>());

}

 std::mem::size_of::<T>()    T  .       -   ,     ;  T     ,    . std::mem -   ,       ,    ;      10.

2.3. ,    

 : f32 -  , f64 -  .  f   ,   , -    .

    bool.    : true  false.

    char.   char         Unicode;  Unicode    20.     .

 2.3.    .

fn main() {

let mass: f64 = 2.51;

let is_ready: bool = true;

let letter: char = '';

println!("mass = {}, is_ready = {}, letter = {}", mass, is_ready, letter);

}

2.4.   

      .  ,    ,     ,     .   u8,    ,     ;  256  u8  ,      ,   .

 

      ?

     i64?

      u8?

         ?

     bool?  .

         char?

   std::mem::size_of::<i32>()?



   i16  u32,      ,   .

 ,          .

   ,     - 255  256 -    u8,   .

 ,     bool  false   .

  print_type_sizes,    i8, char  f64   .     ;       ,    5  1.




 3.   


3.1.  

 -      ;      .   - ,     ,  ,      .   - ,      ;    ,   .   -         ;  Rust       mut      let.

3.2.    

,   let   mut,  .  mut     "".

 3.1.  .

fn main() {

let count = 3;

println!("count = {}", count);

}

 count   3.         .

 3.2.  .

fn main() {

let count = 3;

count = 4; //    

}

      ,   count    .         ,            .

3.3.  

 mut,   let  ,   .      .

 3.3.  .

fn main() {

let mut count = 3;

println!("count  = {}", count);

count = 4;

println!("count  = {}", count);

}

    :  count -   .   ,      .

3.4.    let

 let         .      :     ,        .     ;        ,      ( 4).

 3.4.  .

fn main() {

let side = 5;

let side = side * side;

println!("    5 = {}", side);

}

        side   .      ;       ,      .

 

     ?

      count = 4,  count   ?

        ?

       ?    .

    ?



     sum   0,     7,  .

 ,      :    "",    "";     .

   3.2.            ,   .

 ,    6      ,    3.4.

  double_in_place,     ,          .          .




 4.   


4.1.  

 -  ,      ;          .  -         ;           .  Copy -  ,     ,    ;     Copy,      12.    -   ,       ;     ,       ,     .

4.2.  

    .  ,     Copy,  :         ,     .     ,     ,  ,   .

 4.1.   .

fn main() {

let first = String::from("");

let second = first;

println!("second = {}", second);

// println!("first = {}", first); //    

}

 String     ,    ( 17);    Copy.   let second = first    second.  first    .

 4.2.     .

fn main() {

let a: i32 = 10;

let b = a;

println!("a = {}, b = {}", a, b);

}

 i32  Copy.  let b = a   ;     .  a   .

4.3.     

        ,      Copy.    .      ,       .

 4.3.    .

fn print_city(city: String) {

println!("{}", city);

}



fn main() {

let name = String::from("");

print_city(name);

// println!("{}", name); // : name    

}

   main    print_city.    print_city   .   name    .

4.4.     

       ,    .      ;       .

 4.4.  .

fn make_city() -> String {

String::from("")

}



fn main() {

let city = make_city();

println!("{}", city);

}

 make_city     .   city.       city.

 

        ?

     first   4.1  ?

   let b = a   String  i32?

   ,   ,   ,    ?

          ?



 ,        ;      .

 ,        ;   .

    4.1.        ,  .

  take_ownership,  ,  ,            .   .

  make_two_cities,    ;       main   .         ;   (,  6)  .




 5.   


5.1.  

 - ,     ,    .    &,   .  -             .   - ,   ,    ;   &.   - ,   ;   &mut.   -           ,    ,   ;              .

5.2.  

     .      .

 5.1.   .

fn word_count(text: &String) -> usize {

text.split_whitespace().count()

}



fn main() {

let sentence = String::from("     ");

let n = word_count(&sentence);

println!("sentence = {}", sentence);

println!("  = {}", n);

}

 word_count(&sentence)    ,    sentence.    ;      .  sentence    ,     ,    4.

 usize -   ,         ;     .

5.3.  

     .    &mut  .          ;   ,   ,      .

 5.2.   .

fn append (text: &mut String) {

text.push_str("!");

}



fn main() {

let mut greeting = String::from("");

append (&mut greeting);

println!("{}", greeting);

}

      ,      .  greeting  ;    .

5.4.   

           .    ,     .

 5.3.   .

fn main() {

let mut text = String::from("");

let r1 = &text;

let r2 = &mut text; // :    r1

println!("{}", r1);

}

    r2,    r1   . ,     ,    :     ,     .

 

          ?

   ?

         ?

            ?   .

    ,     ,   ?




  .


   .

   ,     (https://www.litres.ru/book/georgiy-dimitriadi/vvedenie-v-iazyk-programmirovaniia-rust-75040774/)  .

      Visa, MasterCard, Maestro,    ,   ,     ,  PayPal, WebMoney, ., QIWI ,       .


