Tuesday, March 17, 2020

Borrowing and Ownership in Rust

0 lượt xem comment 0 comments

Rust is a pretty interesting language. I said that not because of unique performance but also because it makes you think differently. Languages that make you think differently are great even if you dont use them in production. Rust is quite unique because it does not have Runtime like Java and neither a traditional Garbage collection. Rust managed to be efficient thanks to its's smart compiler and some new rules like Borrowing and Ownership. So I recorded a quick video to explain how Borrow and Ownership work in practices. I hope you like and have fun learning Rust.  Let's get started!

Video

Rust: Borrowing and Ownership from Diego Pacheco on Vimeo.

Code

fn main() {
dont_move_me();
dont_move_me_now();
}
fn dont_move_me(){
let my_string = String::from("This is Diego Rust String.");
let _x = &my_string;
println!("{:?}",my_string);
}
fn dont_move_me_now(){
let mut v = Vec::new();
v = printme(v);
for i in 0..10 {
v.push(i);
}
v = printme(v);
printme(v);
}
fn printme(v:Vec<i64>) -> Vec<i64> {
println!("{:?}",v);
return v;
}
view raw main.rs hosted with ❤ by GitHub


Cheers,
Diego Pacheco
Tags: video,

comment 0 comments

Chuyên mục văn hoá giải trí của VnExpress

.

© 2017 www.blogthuthuatwin10.com

Tầng 5, Tòa nhà FPT Cầu Giấy, phố Duy Tân, Phường Dịch Vọng Hậu, Quận Cầu Giấy, Hà Nội
Email: nguyenanhtuan2401@gmail.com
Điện thoại: 0908 562 750 ext 4548; Liên hệ quảng cáo: 4567.