Rust Programming Tutorial #16 - References

preview_player
Показать описание
In this video I talk about references and borrowing in Rust - there are two types of references: immutable and mutable.

Immutable references don't allow you to change the value of the resource you are referring to while mutable references do allow this.

As read from the Rust documentation:

- You can have multiple immutable references to a variable in the same scope.

OR

- You can have 0 or exactly 1 mutable reference to a variable in the same scope.

Only one at a time.

If this video helped you out and you'd like to see more, make sure to leave a like and subscribe to dcode!
Рекомендации по теме
Комментарии
Автор

I really wanna appreciate the simple introduction to any rust feature in all of this quick tutorials.
It is incredibly useful to start learning Rust language from simple point of view that will be advanced later on trough experience by codding.
Big thanks for every single video in this entire playlist 👌👍

amuerta
Автор

me watching this video at 3am to learn rust
tut: light theme
my eyes: *burned*

boredduck
Автор

So is nobody gonna mention he increased his stardom (*dom)

nrdy
Автор

i think this video at 03:50 should update. because rustc has update the borrow checker, and the code can cargo run success

juqdekm
Автор

Is it update of Rust or smth but the next code runs successfully without shadowing(I'm using rustc 1.33.0):

fn main() {
let mut age = 16;

let nayz = &mut age;
*nayz += 1;

println!("age equals {}", age);
}

inu
Автор

Man what is that keyboard? it sounds super nice

madamadadane
Автор

X is a physical copy of a video game
Dom borrows X
I can't play X until Dom gives it back

aortizc
Автор

3:23 for me working good as mut referenced!, i guess rust update this part

kamalkamals
Автор

is it same between `let mut dom = &x;` and `let dom = &mut x;` ?

sugiono
Автор

append println!("{}"dom) to reproduce the same error. At the time, dom's life seems over before print x.

TheChener
Автор

I think it is not exactly true that there cannot be an immutable reference and at the same the mutable one. I've just tested it out and it works, but the case is that the last reference can only be used.

fn main() {
let mut name = "Edziu";

let refName = & mut name;
*refName = "Janusz";

let refN2 = &name;

println!("{}", refN2)
}

scshout
Автор

@dcode same code is running fine on fine my machine. rustc 1.37.0 (eae3437df 2019-08-13). Any reason?

fahimpatel
Автор

There is no explanation as to what a reference is. It appears to be just about the mechanics of reference. "Why should I care about the reference?", that was the question when I watched.

curtispenner
Автор

hello dom i followed your video my result was very different from yours
here after refrencing
*dom = &mut x;
println!(x is {}, x)
my answer was 11 i also have pic of rust playground
is there a bug or version change..

gamersvideoclips
Автор

2:52 Oh ! icic mustable reference ( &mut ) ! change X through dom !

exoticcoder
Автор

What is the * for?

I do not understand.

brentsteyn
Автор

fortunately* that's not how it works.

bocckoka
Автор

Good intro but this topic needs to be covered in more depth.

rlrl
Автор

"that looks like it's gonna work" yup, that's Rust for you.

whywhatwherein
Автор

Your opening example with Domenic and Dom was really bad. That's aliases, not references.

tetlamed
welcome to shbcf.ru